UISwitch *switchView = [[UISwitch alloc] initWithFrame:CGRectZero];
cell.accessoryView = switchView;
[switchView adTarget:selfaction:@selector(switchChanged:)forControlEvents:UIControlEventValueChanged];
[switchView release];
I allocated switch view in tableView: cellForRowAtIndexPath:.
Do I have to release cell.accessoryView in dealloc?
Isn’t this better than above?
cell.accessoryView = [[[UISwitch alloc] initWithFrame:CGRectZero]autorelease];
You can release your switch as soon as you set
cell.accessoryView. There isn’t much difference between the 2 snippets, except it is generally recommended that you should release the memory explicitly wherever you can.Autoreleaseis generally used otherwise, such as when you have to return a value from a method.