UITableViewCellがあり、ラベルにsubViewを追加します。
[cell addSubview:stateLabel];
ユーザーがセルを押したときにラベルを変更したい。
[tableView indexPathForSelectedRow];
これにより、押されたindexPathが得られますが、ユーザーが押した位置でラベルを変更する方法を教えてもらえますか?
ヒントが必要なだけで、あとは自分でできると思います...
たとえば、ユーザーがセル8を押すと、セル8のstateLabelsubviewが変更されます。
これは私がこれまでに得たものです:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"CellID";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
stateLabel = [ [UILabel alloc ] initWithFrame:CGRectMake(240,0,100,44)];
stateLabel.textColor = [UIColor redColor];
stateLabel.backgroundColor = [UIColor clearColor];
stateLabel.font = [UIFont fontWithName:@"Arial Rounded MT Bold" size:(13.0)];
stateLabel.text = @"Not applied";
[cell addSubview:stateLabel];
}
cell.textLabel.text = [cheatNames objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSIndexPath *selectedRowPath = [tableView indexPathForSelectedRow];
}
ありがとう!