我使用viewDidLoad
中的数组初始化表中的数据,然后将数据添加到单元中。这是我读书的一种标准方式。 这是我有:如何更新tableView中的数据?
- (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;
}
所以,当视图加载,这两个货币价值都在我的表。 现在在另一个函数中,我使用不同的货币编号填充另一个数组,具体取决于用户在文本字段中输入的内容。我将如何更新我当前的表视图,并用我的另一个数组中的值替换这些值?谁能帮我?谢谢!
我得到了重新加载数据的工作,谢谢。但我在填充数组中的值时遇到问题?你能详细说明怎么做吗? – serge2487 2011-03-30 06:08:46
这取决于。获得新值后,是否需要返回初始值?什么是你的表更新值。很难说没有更多的信息。 – Jamie 2011-03-30 06:29:52
我有一个textfield委托“shouldChangeCharactersInRange”,我用该方法中的数字填充数组。所以阵列不断变化。我不在乎旧的价值观。每次调用方法时,我只想获取数组值并将其放入表中。 – serge2487 2011-03-30 07:05:42