iphone - 如何通过按 iPhone 中的按钮将行/单元格动态添加到 UITableView

标签 iphone objective-c uitableview

最初我有一个只有一个添加按钮的表格 View 。

当用户按下此按钮时,我需要增加单元格计数并按如下方式添加单元格

如何写入行数以及如何通过单击添加按钮添加新行

//行数

 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{
    return **????** ;
}

//单元格/行上的内容

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
       ??????
}

//### 添加新行.. ###

-(IBAction)myAction:(id)sender
{
    ???????? ;
}

提前致谢...

最佳答案

UITableView 具有插入行或部分的属性。见Apple Doc

这方面有很多教程。有 2 个常用来添加/删除行/节。

insertRowsAtIndexPaths:withRowAnimation:
deleteRowsAtIndexPaths:withRowAnimation:

我已经发布了类似的答案如何使用它: Hiding the table view cells with switch ON/OFF in iPhone

关于iphone - 如何通过按 iPhone 中的按钮将行/单元格动态添加到 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10408232/

相关文章:

iphone - 类似杂志的版式是如何制作的?

iphone - 动态 iPhone 应用程序图标?

iphone - 如何在 iBooks 上搜索桌面 UI

ios - 我将 NSString 放入 NSUUID 中,但我记录了错误的 UUID iOS

ios - TableView scrollToRow 阻塞了主 ui 线程

ios - TableViewCell 中用于打开 map 应用的按钮

ios - UITableViewCell 宽度不根据 ios 设备类型动态调整

iphone - pjsip在xcode4.2上的编译问题

objective-c - Obj-C文本字段,浮点值和SIGBART

ios - 从 objective c 转到 swift