So i have narrowed my problem down: I have 2 buttons, which are created in the viewDidLoad method, which also initializes what action methods they use, which appears after clicking on a table cell in the previous controller. After i click one i want them both to disable. I have achieved this. However, if someone navigates back to the table view, and then enters the same cell, the buttons are re-enabled. How can I preserve the state of these buttons as disabled if i have clicked one, and then after returning to the table view controller, if i click on the same cell, they remain disabled, but not if i click on a new cell?
So i have narrowed my problem down: I have 2 buttons, which are created in the viewDidLoad method, which also initializes what action methods they use, which appears after clicking on a table cell in the previous controller. After i click one i want them both to disable. I have achieved this. However, if someone navigates back to the table view, and then enters the same cell, the buttons are re-enabled. How can I preserve the state of these buttons as disabled if i have clicked one, and then after returning to the table view controller, if i click on the same cell, they remain disabled, but not if i click on a new cell?
Set up a boolean instance variable buttonsEnabled.
Create a method configureButtons that reads the buttonsEnabled iVar and uses it to either enable or disable your buttons.
Make your button click method set buttonsEnabled to FALSE and then call configureButtons.
Also make your viewWillAppear method call configureButtons.
That way, when the view is getting ready to display, the buttons get set up with the saved buttonsEnabled state.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
thank you very much for the reply, however, i think i will have a similar problem. You see, i have one viewController class called "VoteViewController" which makes 2 buttons and so forth, and gets its display information from my tableViewController class based on which cell you click. So if i my solitary view controller has 1 flag, then all the cell's that i click on will suffer the state that one before it did right?
thank you very much for the reply, however, i think i will have a similar problem. You see, i have one viewController class called "VoteViewController" which makes 2 buttons and so forth, and gets its display information from my tableViewController class based on which cell you click. So if i my solitary view controller has 1 flag, then all the cell's that i click on will suffer the state that one before it did right?
So make your enableButtons flag a property, and set the flag in the table view controller just before pushing the vote view controller. That way the table view controller can control the button state in the vote view controller.
Are you saying that each entry in your table view should remember the enabled/disabled state of the buttons that get displayed in the vote view controller? In that case, you'd need to create an array of flags, one for each entry in your table, and use that to set the state of the enableButtons property before displaying your vote view controller. Make sense?
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
Thank you again, but that last thing you described is EXACTLY what i started coding before i read this! but thank you very much! i will see if it works!
still problems.... so i have 2 ints decalared in my VoteViewController class that handle how big the mutable array of flags should be and the current row that it came from in the previous controller. however, now the buttons just start off disabled and stay that way, even tho i initialize the array as such:
all i see in out put is 0,0,0,0,0,0, when it is CLEARLY supposed to YES, or 1.
where should i initialize this array, because it seems in viewDidLoad i will either have the same array everytime, or it wont work it all like its doing....
still problems.... so i have 2 ints decalared in my VoteViewController class that handle how big the mutable array of flags should be and the current row that it came from in the previous controller. however, now the buttons just start off disabled and stay that way, even tho i initialize the array as such:
all i see in out put is 0,0,0,0,0,0, when it is CLEARLY supposed to YES, or 1.
where should i initialize this array, because it seems in viewDidLoad i will either have the same array everytime, or it wont work it all like its doing....
When do you alloc/init the buttonStates array? It sounds to me like buttonStates is nil. (you can send any message to a nil object and the result you get back is 0 {or nil}.)
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
Good god, i have a check statement that asks what the value is before i insert it and it says 1... GOD I HATE OBJECTIVE C THIS IS SO STUPID
To quote Hal from "2001, a Space Odyssey":
"Sit down, take a stress pill, and think things through."
You can display an array directly, and it will show you each element in the array. So after your loop is finished, you could add a log statement like this:
Code:
NSLog(@"buttonStates array = %@", buttonStates);
My guess is that you forgot to initialize the array, and it's nil.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
alright, so buttonStates = [NSMutableArray array] worked, got some unrecognized selector problems now but ill report back.
Post the header where you declare buttonStates, as well as the code that alloc/inits the variable.
Here's the deal.
When you declare an instance variable, it's just a pointer. The system sets that pointer to nil (or zero).
You have to create an object and set the pointer to point to the newly created object.
Your code
Code:
buttonStates = [NSMutableArray array];
creates a mutable array object, but it creates an autorleased object. That's a temporary object that will go away unless somebody takes ownership of it by sending it a retain message. So in the line above, buttonStates now contains a pointer to a mutable array that has no owner, and is slated for destruction.
You should probably make buttonStates a retained property, and then use code like this:
Where the value for capacity (50 in this case) is a guess as to how big the array is going to grow. If you get guess exactly, great. If not, the array will grow to accommodate more objects, but at the cost of taking extra time to do so.
By making buttonStates a property declared like this:
You tell the system to generate glue code (a "setter") that retains any object you pass in to the property. (and release any old object stored in the property.)
Then, if you add this line to your dealloc method:
Code:
self.buttonSates = nil;
You release any object that was in buttonStates before your object is deallocated, and avoid a memory leak.
The reason that you are having a frustrating time is that you haven't learned the basics. You're slapping together code without understanding the principles behind it, and that doesn't work. Computers are really, really picky. You have to get things perfect, or the program fails - often spectacularly.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
alright i did [buttonStates retain] in my viewDidLoad method and it worked, but now i am back to my god damned original problem, when it reloads the buttons are re-enabled....
and i will agree i do not have the basics of all the memory management. however, this is the way i learn with trial and error. So i am in the process of learning the basics, i just do not want to read a book, that's not how i learn. I have to actively read/do it. however i have everything declared as you said i should. now my problem is that the viewDidLoad is resetting my array.(i think).
by the way thank you so much for your continued response and patience.
OKAY ! good news. What i did was in the previous table Controllers ViewDidLoad method I initialize the array with all YES. When i push the new view, i set a mutable array to be that of the array i loaded in the previous view.
Then, when i click a button, I set them disabled, replace the index in the array with the row that had clicked it with NO, then i go back into and it is still disabled and displaying my votes! Now, in my viewDidUnload method of the VoteViewController class, I set the array in the previous viewcontroller to be the array that i just changed. (i can forsee too much memory being used to do a simple task, but this working now is good enough for me). Since i have the 2 classes in a navigation controller, it doesnt reload the Array with YES's becuase the tableViewController viewDidLoad is not called again when navigating back. I had to do some fancy workarounds with another class i needed the same behaviour with, which involved giving it a whole array of stuff when all i need is an int value, but oh well.
If you see a huge glaring problem, please let me know, otherwise its working as i had wanted(despite possible memory issues).