0

getData()はこのメソッドの最後に一度だけ呼び出されるため、おそらく私のコードは次のメソッドでクラッシュします。

さらに、didSelectRowAtIndexPathコードは次のとおりです。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)newIndexPath
{
    [tableView deselectRowAtIndexPath:newIndexPath animated:YES];

    // Set 
    [[GlobalObject obj] setData:[(CustomCell*)[tableView cellForRowAtIndexPath:newIndexPath] getData]];
}

キャッチされなかった例外'NSInvalidArgumentException'が原因でアプリを終了しています。理由:'-[CustomCell getData]:認識されないセレクターがインスタンスに送信されました

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{   
    if(indexPath.section == 0)
    {
        ...
        return cell;
    }
    else
    {
        // Create a button table view cell
        CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:@"CustomCell"];
        if (cell == nil) 
        {           
            cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CustomCell"] autorelease];
        }

         [cell setButton:[ ...];

        return cell;
    }
}

上に示したように、セルは自動解放され、おそらくこれがアプリがクラッシュした理由です。セルは自動解放プールに移動し、getDataが認識されないセレクターに送信されました。どうすれば問題を解決できますか?

4

1 に答える 1

0

CustomCellには、getDataというメソッドはありません。
インライン化を避け、ステートメントを次々に記述します。これはデバッグに役立ちます。その後、ブレークポイントを簡単に設定できます。

于 2012-12-12T11:54:44.847 に答える