在主視圖中,應用程序xcode生成帶有表格視圖和加號按鈕的就緒應用程序。我想更改該按鈕來添加一個新的單元格,但不包含日期,因爲它是默認的。我想添加兩個文本字段,如label-> textfield,label-> textfield。如何在按下按鈕後將UITextField插入到UITableView中
在代碼中,我有這樣的:
- (void)viewDidLoad{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)];
self.navigationItem.rightBarButtonItem = addButton;
self.detailViewController = (GCDetailViewController *) [[self.splitViewController.viewControllers lastObject] topViewController];
}
和功能:
- (void)insertNewObject:(id)sender{
if (!_objects) {
_objects = [[NSMutableArray alloc] init];
}
[_objects insertObject:[UITextField alloc] atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
謝謝
格式化您的代碼..... –
ok @AnoopVaidya – PurpleMonk