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 namedAppDelegate. 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
AppDelegateclass.[controller insertObject:newItem inListAtIndex:[controller countOfList]];This assumes that your
AppDelegateclass has a method namedinsertObject:inListAtIndex:on it. For the class I linked the method looks like this:So in this case, that method is adding the object to a member variable of your
AppDelegateclass calledList.