更新表视图中的标签
我有一个表视图,其中显示数据库每个元素的名称。其中一个字段是该元素的价格。
我使用这个 UILabel 来显示所有价格的总和,它工作得很好。
- (void)viewWillAppear:(BOOL)animated
{
conto = [[NSNumber alloc] initWithDouble:0];
shoppingListItems = [[NSMutableArray alloc] init];
[super viewWillAppear:animated];
[self loadDataFromDb];
[self sortListArray];
[self.tableView reloadData];
if ([conto intValue] < 0) {
walletLabel.textColor = [UIColor redColor];
} else { walletLabel.textColor = [UIColor greenColor]; }
walletLabel.text = [[NSString alloc] initWithFormat: @"Saldo: %@€", [conto stringValue]];
}
“conto”变量在“loadDataFromDB”方法内计算。
我想每次从表中删除一行时更新它。
有什么建议吗?
I have a table view where is showed the name of every element of a database. One field is the price of that element.
I use this UILabel to show the sum of all the prices, and it works perfectly.
- (void)viewWillAppear:(BOOL)animated
{
conto = [[NSNumber alloc] initWithDouble:0];
shoppingListItems = [[NSMutableArray alloc] init];
[super viewWillAppear:animated];
[self loadDataFromDb];
[self sortListArray];
[self.tableView reloadData];
if ([conto intValue] < 0) {
walletLabel.textColor = [UIColor redColor];
} else { walletLabel.textColor = [UIColor greenColor]; }
walletLabel.text = [[NSString alloc] initWithFormat: @"Saldo: %@€", [conto stringValue]];
}
"conto" variable is calculate inside "loadDataFromDB" method.
I would like to update it every time I delete a row from the table.
Any suggestion?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简单的。只需在
tableView:commitEditingStyle:forRowAtIndexPath:
方法中调用更新例程即可。Easy. Just call your update routine in your
tableView:commitEditingStyle:forRowAtIndexPath:
method.