2011-01-14 47 views
0

嘿!我很抱歉,如果這個問題以前已經被問到過,但我已經在谷歌搜索論壇,我找不到合適的答案。我有一個UITableView,我只想在按下按鈕時添加數據。這個按鈕是一個自定義按鈕,而不是常規的+按鈕。任何幫助,將不勝感激!如果有鏈接可能有幫助,請張貼它!謝謝!按下按鈕時向UITableView添加一行

回答

0
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation 

從UITableView的Docs

+0

謝謝Terente。所以如果我在IB中創建一個按鈕並將其連接到這個方法,我可以添加文本到我的行? – narda 2011-01-14 13:23:44

0

創建一個自定義按鈕,並在界面生成器把它掛到這個方法:

- (IBAction)buttonPressed:(id)sender{ 

    //Assuming you have an NSMutableArray named cellData 
    //as the datasource for your table: 

    //add to datasource 
    [[self cellData] addObject:[@"Cell " stringByAppendingFormat:@"%d", indexPath.row]]; 

    //add to table with a animation form the right 
    NSIndexPath *path = [NSIndexPath indexPathForRow:[[self cellData] count] - 1 inSection:0]; 
    NSMutableArray *rows = [NSMutableArray arrayWithObject:path]; 
    [[self tableView] insertRowsAtIndexPaths:rows withRowAnimation:UITableViewRowAnimationRight]; 

}