2

UITableView に CustomCells を設定しており、didSelectRowAtIndexPath を呼び出そうとしています。カスタム セルのヘッダーは次のとおりです。

#import <UIKit/UIKit.h>

@interface CustomCell : UITableViewCell {
    IBOutlet    UILabel         *bizNameLabel;
    IBOutlet    UILabel         *addressLabel;
    IBOutlet    UILabel         *mileageLabel;
    IBOutlet    UIImageView     *bizImage;
}

@property (nonatomic, retain) UILabel     *bizNameLabel;
@property (nonatomic, retain) UILabel     *addressLabel;
@property (nonatomic, retain) UILabel     *mileageLabel;
@property (nonatomic, retain) UIImageView *bizImage;
@end

かなりシンプルで簡単です。セルのcellForRowAtIndexPathメソッドにもセルに追加しているdetailDisclosureButtonがあり、メソッドaccessoryButtonTappedForRowWithIndexPath:が呼び出されていますが、didSelectRowAtIndexPathはそうではありません。

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

    static NSString *CellIdentifier = @"CustomCell";

    CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) 
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCellView" 
                                                     owner:self options:nil];

#ifdef __IPHONE_2_1
        cell = (CustomCell *)[nib objectAtIndex:0];
#else
        cell = (CustomCell *)[nib objectAtIndex:1];
#endif
    }

    // Configure the cell.
    NSDictionary *dict = [rows objectAtIndex: indexPath.row];

        /*
          CODE TO POPULATE INFORMATION IN CUSTOM CELLS HERE
       */

#ifdef __IPHONE_3_0
    cell.accessoryType =  UITableViewCellAccessoryDetailDisclosureButton;
#endif

    return cell;
}

すべてのメソッドとブレークポイント内に NSLog を配置しました。私が呼び出そうとしているメソッドはそうではありませんが、私の CustomCell クラス内では、次のメソッドはそうです。CustomCell の使用中に didSelectRowAtIndexPath を呼び出す方法はありますか?

- (void)setSelected:(BOOL)selected animated:(BOOL)animated 
4

4 に答える 4

1

カスタム セルの有無に違いはありません。編集モードですか?その場合は、allowsSelectionDuringEditing = truetableView に設定する必要があります。

于 2011-07-15T02:50:54.847 に答える
0

xibでTableviewを使用している場合..だから、tableviewのデータソースを指定し、ファイル所有者に接続を委任したい..

于 2011-07-15T05:08:21.357 に答える
0

myTableView の親ビューに UITapGestureRecognizer が設定されているかどうかを確認してください。おそらく、タッチ イベントに乗ってそれを消費しています。

于 2012-12-01T03:37:30.870 に答える
0

それが呼び出されていると言うのでtableView:accessoryButtonTappedForRowWithIndexPath:、tableView のデリゲート プロパティが適切に設定されていることがわかります。そのtableView:didSelectRowAtIndexPath:ため、同様に呼び出される必要があります。呼び出されない場合は、メソッド シグネチャのどこかにタイプミスがあると考えられます。このメソッド シグネチャをコピーしてコードに貼り付け、誤って "tableView:" の部分を省略したり、大文字と小文字を間違えたりしていないことを確認してください。

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

編集: 二次仮説: カスタム セルを定義した .xib で、[ユーザー インタラクションを有効にする] がオンになっていることを確認します。

于 2011-07-15T05:44:43.860 に答える