我有一個TableView中的產品列表。該列表由WCF調用填充。我可以在日誌中看到產品正在加載正確的值。其中一個值是一個名爲Bought的布爾值。我想用它來顯示(與上tableviewCell標記),如果產品是買還是不單元格上的accessoryType不變
在這裏,我裝入電池:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ProductCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
// Configure the cell...
id prod = [_productList objectAtIndex:indexPath.row];
cell.textLabel.text = [prod ProductName];
NSString *stringAmount = [NSString stringWithFormat:@"%@", [prod Amount]];
cell.detailTextLabel.text = stringAmount;
if (![prod Bought]) {
cell.accessoryType = UITableViewCellAccessoryNone;
}
else
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
return cell;
}
這裏我更改值
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self markBought];
[tableView reloadData];
[self reloadInputViews];
}
的didSelectRowAtIndexPath
方法的工作(我可以看到價值在數據庫中更改) 但對號始終是 -
我懷疑我加載Accessorytype錯誤 - 但我真的不知道如何做不同。
取代
甲產品出來這樣的: '假 1一:ProductId>Æg a:ProductName> '' –
catu
'[prod Bou ght]'返回一個標量(例如'BOOL')還是一個對象(例如'NSNumber')?在後一種情況下,您可能需要檢查'if(![[prod bought] boolValue]){...}' –
完美 - 謝謝:) – catu