Edit Individual Cell In NSArray
I ha开发者_开发百科ve an array with 10 objects and I put this into a table. How can I edit one of the individual objects in the array or refresh it?
All the objects just hold text, so after I change the text how can I refresh the array? See where I am coming from?
Thanks.
NSArray is an immutable class, which means that its contents can't be changed after it has been created. If you want to be able to change the contents of your array after it has been created, you should use an NSMutableArray instead. This subclass of NSArray provides additional methods such as:
insertObject:atIndex:
removeObjectAtIndex:
addObject:
removeLastObject
replaceObjectAtIndex:withObject:
Once you've updated your mutable array, you can reload your table by calling [self.tableView reloadData]
.
EDIT:
If you just want to change the value of one of the elements in your array without actually adding or removing any objects, then your array doesn't need to be mutable, but the object you're changing does. So if you have an array of NSString objects, you can change those to NSMutableString objects. Then you can use setString:
on one of those objects to change its value.
You can, for example, show editing screen on table row selection, save editing and refresh table on hiding editing screen.
精彩评论