UITableView在应用程序运行时添加行

时间:2012-09-21 13:22:58

标签: ios objective-c cocoa-touch

我创建了一个新的View控制器,并添加了“Table View”。 我添加了插件到控制器代码和viewDidLoad方法我尝试添加一个新行。

我有简单的数据源NSMutableArray和文本(表格就像“名人堂”)。

如何插入包含数组文本的行?

@property (strong, nonatomic) IBOutlet UITableView *fameTable;
@property (weak, nonatomic) NSMutableArray *dataSource;
...
[self.dataSource addObject:@"New Item"];
[self.dataSource addObject:@"New Item 2"];
[self.dataSource addObject:@"New Item 3"];

2 个答案:

答案 0 :(得分:0)

看一下表视图的insertRowAtIndex方法.. 它插入行而不重新加载整个tableview .. 请在发布此类问题之前进行一项小型研究..这是一个非常常见的问题.. 我希望它能帮助你!欢呼声!!

她是一个关于表格视图基础知识的小教程:

http://www.mobisoftinfotech.com/blog/iphone/introduction-to-table-view/

答案 1 :(得分:0)

after adding is done ..

    [fameTable reloadData];

dont forget to implement the datasource method

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

   return  [datasource count];

    }
相关问题