2012年8月22日 星期三

Use UISwitch in custom UIViewTableCell

I use UISwitch in my cells and can do add, edit and delete.

But UISwitch is always disappeared after change to ON of OFF.
I search Google and find a lot of developer has this issue and spend a lot of time to debug.

Finally, this bug has removed. Why?

Don't put the code to the cell configure function and that will let you run the code several times.

    cell.accessoryView = enableUISwitch;
    cell.editingAccessoryView = enableUISwitch;


Use accessoryView is good because you need to get UISwitch status: ON or OFF.



- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
       atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
      newIndexPath:(NSIndexPath *)newIndexPath

Then you can use didChangeObject to get which row of UISwitch's status otherwise it can't be got.

It is only just run one time enough. 


This bug makes me almost crazy for two days.

沒有留言:

張貼留言