2

UIImageView と UIButton を追加した Interface Builder で UITableViewCell を作成しました。UIButton にアウトレットを与え、イベント セット内のタッチアップを使用して IBAction に接続しました。すべてが接続されているように見えたので、このメソッドを呼び出すと想定しました。

- (IBAction)pressedCheckbox:(id)sender {
    [sender setBackgroundImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateNormal];
    NSLog(@"clicked check");

}

接続タブを確認すると、アウトレットとアクションのすべてが正しく設定されています。エラーは発生しませんが、アプリをプレビューするときに UITableViewCell 内のそのボタンをクリックしても何も起こらず、ログには何も表示されません。

UITableViewCellにあるボタンをクリックできない理由についてのアイデアは?

編集:

cellForRowAtIndexPath のコード:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        cell.editingAccessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }

    if (indexPath.section == 0) {
        switch (indexPath.row) {
            case 0:
                cell = topCell;
                break;
            case 1: 
                cell = cell1;
                break;
        }//end switch

    }//end if

    return cell;
}
4

3 に答える 3

1

私はまた、問題が何であるかを理解しました。セルに異なる高さを設定する必要があり、以下を使用していました。

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

     if (indexPath.section == 0) {

          switch (indexPath.row) {

               case 0:

                    return 26;

                    break;

          }//end switch

     }//end if

     return tableView.rowHeight; <-- I just added this and it fixed the issue

}

以前はセル0の値しか返さなかったため、他のすべてのセルで問題が発生していました

于 2010-08-26T23:55:19.373 に答える
0

IBでこれをやっていますか?- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents問題が IB リンクであるかどうかを確認するために (所有しているビュー コントローラーの loadView メソッドで)試してみる価値があるかもしれません。

于 2010-08-26T22:42:43.813 に答える
0

これは UITableViewCell のサブクラスということですか?通常の UITableViewCell の代わりにこれを使用していますか?

メソッドの実装に移動しcellForRowAtIndexPath、セルをインスタンス化する行を探します。UITableViewCellではなく、サブクラスが呼び出されたものにインスタンス化していることを確認してください。混乱している場合は、codeForRowAtIndexPathメソッドのコードを投稿して、確認できるようにしてください。

于 2010-08-26T22:43:57.897 に答える