Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
The problem is that the array seems to be resetting itself every time I press the button. How do I fix this?
As you've already alluded to, you need to put the code that alloc/inits your usrs somewhere where it is only called once (or at least, once before it is needed). Alternatively, you could put some logic in to only alloc/init it when it hasn't been already, similar to "lazy-loading".

P.S. If you have properties declared, you should make an effort to use the synthesized accessors you've defined for it, like you've already done with usrString and passwdString.

P.P.S. I would like to ask: what have you already done to educate yourself in the fundamentals of Objective-C / iPhone programming? Books? Videos? Tutorials? Etc? Be as specific as you can when you answer. Thank you.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,737
8,410
A sea of green
The problem is that the array seems to be resetting itself every time I press the button. How do I fix this?

Put the code in a method where it executes only once.

There is one such method that every class is certain to have.
It's always executed once, and only once.
It's always executed before any other instance-method is executed.
You already have this method in your posted code.
It has this comment:
// Custom initialization

If you don't recognize what to do and where to put it, then you definitely need to review the fundamentals of defining classes.

You may be able to postpone learning this by hacking together something that sorta works. But that's exactly how you got to this point: by hacking together things that sorta work without fully understanding them (trust me, I can tell by the posted code). More of the same isn't really going to be all that effective in the long term. And by "long term" I mean "more than a few days".

You seem to be distracted by The Illusion Of Progress that comes from writing code and seeing it do stuff. When coding stops, it seems that progress stops. This is mistaken. When coding stops in order to discover how to proceed, that's progress. And it's the only real progress that will happen over and over again, as you discover something you don't know how to solve, then learn how to solve it, then go on to actually solve it.
 

balamw

Moderator emeritus
Aug 16, 2005
19,366
979
New England
And it's the only real progress that will happen over and over again, as you discover something you don't know how to solve, then learn how to solve it, then go on to actually solve it.

A big part of that process is learning how to poke and prod your code with the many diverse debugging tools at your disposal.

There are dozens of different ways of testing your code: breakpoints, printing intermediate values of variables to the console, printing comments like "Now executing this section of code" to the console, watching variables or expressions, ...

You need to add some of these tools into your arsenal so you can ask the right questions of your code. Not all of the tools will suit your own personal way of approaching the problem or thought process, but hopefully one or more will or you will have a hard time making real progress.

If you don't know how to get started, read a book that can help point you in the right direction: e.g. http://oreilly.com/catalog/9781934356289/

EDIT: As dejo already requested, it would be good to know what path you've taken to get to this point but also where do you intend to go with this? Is this a school project? Fun/self-improvement? Work/training? That would help use point you to other resources that might help you get where you want to go.

B
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.