How to add row in a table on a click event of a Button
i want to add a row in a table on the click event of a Button.for this i am using following code. But it not work.
-(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;
}
where i is a global variable which intialize in viewdidload function by 1; Tha开发者_如何学Cnks in advance for any type of suggestion.Thanks
You can just do it like this on button event increment an instance or global variable like you are using i so the code will look like this
-(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;
}
A little suggestion : Table View Programming Guide for iOS, read that first.
精彩评论