TableView に製品のリストがあります。リストは、WCF 呼び出しによって設定されます。製品が正しい値で読み込まれていることをログで確認できます。値の 1 つは、Bought というブール値です。これを使用して、製品が購入されたかどうかを(tableviewCellにチェックマークを付けて)表示したいと思います
ここでセルをロードします:
- (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 を間違ってロードしていると思われますが、別の方法で行う方法が実際にはわかりません。