I was reading the docs to learn how to add a row in a table view, and I found this example :
- (void)save:sender {
UITextField *textField = [(EditableTableViewTextField *)[tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]] textField];
SimpleEditableListAppDelegate *controller = (SimpleEditableListAppDelegate *)[[UIApplication sharedApplication] delegate];
NSString *newItem = textField.text;
if (newItem != nil) {
[controller insertObject:newItem inListAtIndex:[controller countOfList]];
}
[self dismissModalViewControllerAnimated:YES];
}
I don't understand the method : insertObject:inListAtIndex:
or what [[UIApplication sharedApplication] delegate];
stands for; are we putting the data in a plist file? Could someone explain this to me? The UIApplication
docs do not really help.
[[UIApplication sharedApplication] delegate]
is the main application delegate, typically this is a class named AppDelegate
. The main application delegate is the one that is created on application start-up and which is the main controller for your application.
I'm going to assume that you're using something similar to this class as your AppDelegate
class.
[controller insertObject:newItem inListAtIndex:[controller countOfList]];
This assumes that your AppDelegate
class has a method named insertObject:inListAtIndex:
on it. For the class I linked the method looks like this:
- (void)insertObject:(id)obj inListAtIndex:(NSUInteger)theIndex {
[list insertObject:obj atIndex:theIndex];
}
So in this case, that method is adding the object to a member variable of your AppDelegate
class called List
.
reloadData
to refresh the table view? Thank - Paul 2012-04-04 21:28
controller
variable IS your app delegate. Part of the problem is that this is not a good example of how to create a uitableviewcontroller. Start http://developer.apple.com/library/ios/#DOCUMENTATION/UserExperience/Conceptual/TableViewiPhone/AboutTableViewsiPhone/AboutTableViewsiPhone.html#//appleref/doc/uid/TP40007451 and if you have more questions post another one - mydogisbox 2012-04-04 21:37
There is no connection to plist. Just message exchange with help of delegates to change table view.
From apple documentation:
When a table view enters editing mode and when users click an editing control, the table view sends a series of messages to its data source and delegate, but only if they implement these methods. These methods allow the data source and delegate to refine the appearance and behavior of rows in the table view; the messages also enable them to carry out the deletion or insertion operation.
And one of the best books - Beginning iphone 4 (or 5)