UITableViewCell disable cell, then re-enable and update without reloading view

Go To StackoverFlow.com

0

I have found a multitude of questions asking almost what I am after, but have been as of yet unable to implement my own solution.

I have 2 sections in my UITableViewController, and everything works fairly well so far. I have an AlarmEnabled UISwitch, and an AlarmDate cell, which pulls up a UIActionSheet so that one can choose the fire date, etc. I am attempting to disable/grey-out the AlarmDate cell (cell 0) when one negates the AlarmEnabled UISwitch in "real time". This does work, but only if I a) Negate UISwitch b) Exit view by the Cancel/Save UIButton c) Re-enter the view.

I have so far tried the tableView:reloadRowsAtIndexPath: method as follows:

NSIndexPath *tempIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
NSArray *tempIndexPathArray = [[NSArray alloc] initWithObjects:tempIndexPath, nil];
[self.tableView reloadRowsAtIndexPaths:tempIndexPathArray withRowAnimation:UITableViewRowAnimationNone];
[tempIndexPathArray release];

Perhaps due to my on-off relationship with iOS programming, I just misunderstand where that code should be placed (currently placed within the selector for the AlarmEnabled UISwitch accessory), but it doesn't do what i'm after (but sounds like it should if used correctly).

I thought i'd try to increase my cognition and try something like the following in the selector for the UISwitch,

#define NOT(a)  !a
....
UITableViewCell *tempCellAlarmDate = [self.tableViewController.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
tempCellAlarmDate.userInteractionEnabled = NOT(tempCellAlarmDate.userInteractionEnabled);
// forget transparency for now.
//tempCellAlarmDate.alpha = 0.0;

.. but the briskly-trotting rodent powering the dynamo in my skull does not approve of this code, and thus my dream of real-time userInteractionEnabled toggling goes unrealised.

Any advice is appreciated :-)

Thanks

sc.

2012-04-05 14:48
by swisscheese
#define NOT(a) !a - are you kidding - Sulthan 2012-04-05 17:54
@Sulthan -please explain what you mean, rather than posting rhetoric - swisscheese 2012-04-05 20:42
You are using a macro to convert a programming language into you own programming language. This is not a good idea - Sulthan 2012-04-05 21:51
@sulthan - I see your point, but I guess it's a matter of taste. How would one represent a complex bit-twiddling operation? Best done with a macro I think. In any case, thank you for your time - swisscheese 2012-04-06 07:33
Yes, you would create a kind of macro, but not to rename the operators :) This is not a matter of taste. Please, ask the question in the forums. I am sure nobody (maybe few crazy exceptions) will like your solution - Sulthan 2012-04-06 08:08
Ok style police :) Thanks again - swisscheese 2012-04-06 10:53


0

I'm missing where you are calling the setEnabled: method on the cell. Or are you disabling it using some other method? In my experience, setEnabled: NO disables a cell in real time, and setEnabled: YES brings it back. Perhaps I'm missing something?

2012-04-05 15:09
by DRVic
Hi, I am unsure as to which class you are referring to, as UITableViewCell does not seem to contain the setEnabled: method. Can you clarify? Thanks - swisscheese 2012-04-05 16:06
My bad. setEnabled is in NSControl, which is inherited by NSTableViewCell, but not UITableViewCell. You might be able to set the editingStyle property, but I'm not sure whether it has an immediate effect as setEnabled does - DRVic 2012-04-05 19:03
No probs! My search continues :-) Thanks for your time - swisscheese 2012-04-06 07:33
Ads