serge2487 serge2487 - 8 months ago 48
iOS Question

how to update data in tableView?

I initialize data in my table with an array in

and then add the data to the cell. This a standard way of doing it that I read in a book.
This is what I have:

- (void)viewDidLoad {
[super viewDidLoad];
//Create array and add data ("tableViewValues" is initialized in .h file)
tableViewValues = [[NSMutableArray alloc]init];
[tableViewValues addObject:@"$280,000.00"];
[tableViewValues addObject:@"$279,318.79"];

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

NSString *cellValue = [tableViewValues objectAtIndex:indexPath.row];

cell.textLabel.text = cellValue;

return cell;

So when the view loads, those two currency values are in my table.
Now in another function, I populate a another array with different currency numbers depending on what the user enter in a textfield. How would I update my current table view and replace those values with the values in my other array? Can anyone help me? Thanks!


You can call

[self.tableView reloadData];

to reload all data, however, you will need to program a way to have the array that you want populate the table. Maybe you want your -cellForRowAtIndexPath to call a private method that conditionally picks the correct array.