gpt4 book ai didi

ios - 如何更新tableView中的数据?

转载 作者:IT王子 更新时间:2023-10-29 08:10:24 25 4
gpt4 key购买 nike

我使用 viewDidLoad 中的数组初始化表中的数据,然后将数据添加到单元格中。这是我在一本书中读到的一种标准方法。这是我的:

- (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;
}

所以当 View 加载时,这两个货币值在我的表中。现在在另一个函数中,我根据用户在文本字段中输入的内容用不同的货币数字填充另一个数组。我将如何更新我当前的 TableView 并将这些值替换为我的其他数组中的值?谁能帮我?谢谢!

最佳答案

你可以打电话

[self.tableView reloadData];

但是,要重新加载所有数据,您需要编写一种方法来让您想要填充表格的数组。也许您希望您的 -cellForRowAtIndexPath 调用一个有条件地选择正确数组的私有(private)方法。

关于ios - 如何更新tableView中的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5482106/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com