1

我有一个屏幕应该在其中显示 UITableView。我希望允许用户编辑这个表格视图;即添加行、删除行和更改它们的顺序。

当表格视图嵌入在 UINavigationController 中的 UITableViewController 中时,我知道如何执行此操作,因此具有将这些“编辑”和“新建”按钮添加到导航栏的相关属性。

如果我的表格视图在常规 UIViewController 中并且此 VC 未嵌入在 UINavigationController 中,我应该如何处理它?

我找不到任何带有此类示例的教程(它们都显示了我已经知道并且与我的案例无关的导航控制器嵌入场景......)

4

1 回答 1

1

只需将 UIViewController 设置为 tableView 的委托和数据源。如果您查看文档,您会发现有许多有用的委托方法。

http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDelegate_Protocol/Reference/Reference.html

添加您的 UIButton,将其目标方法设置为您自己的,您将在其中使用添加或删除行

[tableView beginUpdates];
        [tableView insertRowsAtIndexPaths:rowArray withRowAnimation:UITableViewRowAnimationAutomatic];
[tableView endUpdates];

请参阅http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableView_Class/Reference/Reference.html#//apple_ref/doc/c_ref/UITableView

主要是插入、删除和移动行和节部分

于 2013-08-05T13:49:34.010 回答