KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I went through all the examples online and could not figure out how to properly add a cell to a tableview with animation. Let's say I have one section with one cell and I want to add another cell once the user clicks on the first cell's accessory. My "add" method does this: - (IBAction) toggleEnabledTextForSwitch1onSomeLabel: (id) sender { if (switch1.on) { NSArray *appleComputers = [NSArray arrayWithObjects:@"WWWWW" ,@"XXXX", @"YYYY", @"ZZZZ", nil]; NSDictionary *appleComputersDict = [NSDictionary dictionaryWithObject:appleComputers forKey:@"Computers"]; [listOfItems replaceObjectAtIndex:0 withObject:appleComputersDict]; [tblSimpleTable reloadData]; } Which is working but there is no animation. I understand that in order to add animation, I need to use insertRowsAtIndexPaths:withRowAnimation, so I tried tons of options but it always crashes when executing the insertRowsAtIndexPaths:withRowAnimation method. My recent try was by doing this: - (IBAction) toggleEnabledTextForSwitch1onSomeLabel: (id) sender { if (switch1.on) { NSIndexPath *path1 = [NSIndexPath indexPathForRow:1 inSection:0]; //ALSO TRIED WITH indexPathRow:0 NSArray *indexArray = [NSArray arrayWithObjects:path1,nil]; [tblSimpleTable insertRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationRight]; } } What am I doing wrong? How can I make this happen easily? I dont understand this whole indexPathForRow thing...I also dont understand how with this method I can add a label name to the new cell. Please help...thanks!!
Tags (comma-separated)
Save Edits
Cancel