0

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];


}

ありがとう!

4

3 に答える 3

1

このようなものを実装できます

cellForRowatIndexPath:戻りセルの前のメソッドで;

indexpathラベルを変更するために選択した行の を取得します。そして使う

if(indexpath == selected index)
{
    // do ur code here

}

呼び出されるとすぐdidSelectRow:にテーブルをリロードします

これは間違いなく機能します。

于 2012-11-09T07:08:29.440 に答える
0

リロードは必要ありません

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSIndexPath *selectedRowPath = [tableView indexPathForSelectedRow];
    myString = @"Any Data";
    [tableView reloadData];

    UITableCellView *cell = [tableView cellAtIndexPath:indexPath];
    cell.label.title = myString;
}
于 2012-11-08T22:32:49.840 に答える
-1

.hmyStringファイルでNSString

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

NSIndexPath *selectedRowPath = [tableView indexPathForSelectedRow];
myString = @"Any Data";
[tableView reloadData];

}
-(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 = myString;
    [cell addSubview:stateLabel];
}

cell.textLabel.text = [cheatNames objectAtIndex:indexPath.row];


return cell;

}
于 2012-11-08T21:08:02.867 に答える