-1

How can I call the default insertNewObject method? I have created a custom button in the storyboard and linked it to an action called addDate, but I don't quite understand what parameter the insertNewObject takes in

- (void)insertNewObject:(id)sender
{
if (!_objects) {
    _objects = [[NSMutableArray alloc] init];
}
 [_objects insertObject:[NSDate date] atIndex:0];
 NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
 [self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}


- (IBAction)addDate:(id)sender {
// have to call insertNewObject
}
MichaelGofron
  • 1,310
  • 4
  • 15
  • 29

1 Answers1

2

(id)sender is a parameter that refers to the UIView that is calling the method, normally a UIButton If you don't need any parameters on this function, just delete :(id)sender and call

[self insertNewObject];

if you actually need a parameter, say a NSString, substitute :(id)sender for :(NSString)parameter or whatever type of parameter you want, and call

[self insertNewObject:yourParameter];
Fabio
  • 3,015
  • 2
  • 29
  • 49