Chilly Zhong
Chilly Zhong

Reputation: 16783

How to add data to TableView on iphone?

I defined an array for tableView's listData.

NSArray *array = [[NSArray alloc] initWithObjects:@"Sleep", @"Bashful", @"Happy", nil];
self.listData = array;

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
cell.text = [listData objectAtIndex:row];

Now I want to add more data to the tableview. How to connect another data to it so when I click a button the array will be @"A", "B", "C", "D", nil?

Upvotes: 0

Views: 7113

Answers (1)

Alexandre L Telles
Alexandre L Telles

Reputation: 3435

The easiest way to do this is to use the NSMutableArray with insertObjetcAtIndex or addObject:

NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:@"Sleep", @"Bashful", @"Happy", nil];
[array insertObject:@"XYZ" atIndex:3];
[array addObject:@"ABC"];

Upvotes: 2

Related Questions