我有以下条目更新标签文本,其值为:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *row = [tableView dequeueReusableCellWithIdentifier:@"TICKET_ITEM"];
UILabel *itemDiscount = (UILabel *)[row viewWithTag:502];
itemDiscount.text = [[arrayOfItem objectAtIndex:indexPath.row]TICKET_ITEM_DISCOUNT];
return row;
}
我的问题是,事实上我有一个允许设置折扣的按钮(最初为0)。调整滑块后,我希望能够获取该折扣%并使用新值更新itemDiscount.text。我认为我需要这样做的方法是更新arrayOfItem TICKET_ITEM_DISCOUNT条目然后使用reloadData。但是,如何仅更新数组中的单个项目?
答案 0 :(得分:4)
在NSArray上查看Apple的documentation。
有多种方法可以解决您的问题。
indexOfObject:
或
indexOfObjectPassingTest:
春天想到了。
要编辑NSArray,您需要制作数组的可变副本,然后再将其分配回来:
NSMutableArray *temp = [arrayOfItem mutableCopy];
//update your value here
arrayOfItem = temp;