按下按钮时向UITableView添加行

时间:2011-01-14 09:57:11

标签: iphone objective-c uitableview

喂!我很抱歉,如果之前已经提出过这个问题,但我已经在google上搜索了论坛,但我找不到合适的答案。我有一个UITableView,我只想在按下按钮时添加数据。此按钮是自定义按钮,而不是常规+按钮。任何帮助,将不胜感激!如果有可能有帮助的链接,请发布!谢谢!

2 个答案:

答案 0 :(得分:0)

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

来自UITableView Docs

答案 1 :(得分: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];

}