0

UITableView多数のカスタムで構成された がありますUITableViewCells

テーブルdidSelectRowAtIndexPathメソッドが起動すると、 the が 2 の場合、この行のセル内でindexPath.rowa を更新したいと思います。UILabel

私の考えは、次の行に沿って何かを使用することでした。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.row == 2){

    myCustomCellView *cell = [self.essentialsTableView cellForRowAtIndexPath:indexPath];
    cell.myUILabel.text = @"my text";

    [tableView reloadData];

  }
}

ここでの問題は、 ではなくcellForRowAtIndexPath型のオブジェクトを返すことです。UITableViewCellmyCustomCellView

メソッド内のセルのプロパティにアクセスして更新する方法を教えてもらえますdidSelectRowAtIndexPathか?

4

6 に答える 6

0

myCustomCellViewのサブクラスですUITableViewCell。したがって、セルをタイプキャストするだけです

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if(indexPath.row == 2){

        myCustomCellView *cell = (myCustomCellView *)[self.essentialsTableView cellForRowAtIndexPath:indexPath];
        cell.myUILabel.text = @"my text";

        [tableView reloadData];

      }
    }

myCustomCellView詳細: Apple のコーディング ガイドラインに従って、ユーザー クラス名は使用する代わりに小文字で始まりませんMyCustomCellView

于 2013-04-23T10:08:25.330 に答える
0

データソースを更新し、テーブルビューをリロードする必要があります

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
if(indexPath.row == 2){

    //update the array which is used as the data provider  in cell for row at index path.

    [tableView reloadData];

  }
}
于 2013-04-22T12:19:50.587 に答える
0
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

 myCustomCellView *cell = [self.essentialsTableView cellForRowAtIndexPath:indexPath];
 UILabel *yourLabel=[cell.contentViews.subviews viewWithTag:indexPath.row+1];
 //do whatever you want with your label;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   // Your code
          cell.myUILabel.text = @"my text";
          cell.myUILabel.tag=indexpath.row+1;
}
于 2013-04-22T11:13:48.020 に答える
0

UITableViewCellカスタムセルへのタイプキャスト

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if(indexPath.row == 2){

        myCustomCellView *cell = (myCustomCellView *)[self.essentialsTableView cellForRowAtIndexPath:indexPath];
        cell.myUILabel.text = @"my text";

        [tableView reloadData];

    }
}
于 2013-04-22T11:17:11.327 に答える
0

「secondRowIsClicked」などの 1 つの Bool 値を定義します。viewWillApperまたはviewDidAppear関数で No に設定します。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
    if(indexPath.row == 2)
    {
        secondRowIsClicked = YES;
        [tableView reloadData];
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   // Your code
   if (secondRowIsClicked == YES)
   {
       cell.myUILabel.text = @"my text";
   }
}
于 2013-04-22T11:10:25.120 に答える