iphone - 在 tableView 上使用 CustomCell,如何调用 didSelectRowAtIndexPath?

标签 iphone didselectrowatindexpath custom-cell

我正在使用 CustomCells 填充 UITableView,并尝试调用 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 

最佳答案

是否自定义单元格应该没有任何区别。您处于编辑模式吗?如果是,则必须在 tableView 上设置 allowsSelectionDuringEditing = true

关于iphone - 在 tableView 上使用 CustomCell,如何调用 didSelectRowAtIndexPath?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6701787/

相关文章:

iphone - self.view = someController.view 与 [self.view addSubview :someController. view]

ios - 以编程方式在 iphone 处于锁定模式时打开相机应用程序

iphone - 我们需要 iPhone/iPad 来开发它吗?

ios - didSelectRowAtIndexPath; UITapGestureRecognizer;自定义 UITableViewCell

ios - 点击另一个单元格时隐藏 datePicker?

IOS 8 自动高度单元工作但当我向上滚动时它跳

iphone - 为什么检测触摸的速度越来越慢?

长按选中的 Swift 3.0 Table View Cell

android - ListView 还是 TableLayout?

ios - IBoutlet 在我的自定义表格单元格中为零?