2011-07-26 30 views
0

我想在Button的click事件的表中添加一行,为此我使用以下代码。但它不起作用。如何在一个按钮的点击事件中添加表中的行

-(void)translation:(id)sender 
{ 
    [self tableView:mainTableView numberOfRowsInSection:1]; 
    i+1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    // Return the number of rows in the section. 
    return i; 
} 

其中i是一个全局变量,它在viewdidload函数中初始化1; 预先感谢任何类型suggestion.Thanks

回答

2

像你使用我,使代码看起来像这样

-(void)translation:(id)sender 
{ 
    i = i+1; 
//This function will automatically call numberofrows and cellforrowatindexpath methods of tableView 
    [tableView reloadData]; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    // Return the number of rows in the section. 
    return i; 
} 
+0

感谢您的帮助。例如,如果我有两个表,我想同时添加行,我怎么能做到这一点。我做了什么在创建表时,我分配了每一个不同的标签,但行只创建2表。 – Rahul

+0

那么代码将只为在两个tableView实例上调用reloadData,就像你有tableView1和tableView2,然后在按钮的tap上调用[tableView1 reloadData]; [tableView2 reloadData];但要确保两个tableView的数据源应该是相同的。如果我根据标签属性区分表,则首先阅读一些UITableView编程指南,Vince建议 –

+0

。那么我怎么能在这两个表中添加行。 – Rahul

相关问题