2014-06-28 19 views
-1

如何調用默認的insertNewObject方法?我在故事板創建自定義按鈕,並將其鏈接到名爲ADDDATE的行動,但我不太明白insertNewObject需要什麼參數如何在IOS中調用默認的insertNewObject方法

- (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 
} 
+0

http://www.informit.com/articles/article.aspx?p=2148655&seqNum=7的[我怎麼能調用的方法 –

+0

可能重複目標C?](http://stackoverflow.com/questions/591969/how-can-i-call-a-method-in-objective-c) – Brandon

回答

2

(id)sender是指UIView正在調用的參數該方法,通常是UIButton 如果不需要此功能的任何參數,只是刪除:(id)sender並調用

[self insertNewObject]; 

如果你確實需要一個參數,說的NSString,替換爲:(id)sender:(NSString)parameter或者任何一種你想要的參數,並調用

[self insertNewObject:yourParameter]; 
相關問題