2

我正在使用 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

非常简单明了。我有一个 detailDisclosureButton,我也在单元格的 cellForRowAtIndexPath 方法中添加到单元格中,并且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 类中,以下方法是。那么有没有办法让 didSelectRowAtIndexPath 在使用 CustomCell 时被调用?

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

4 回答 4

1

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

于 2011-07-15T02:50:54.847 回答
0

检查您是否为 myTableView 的父视图设置了 UITapGestureRecognizer ..这可能超出了触摸事件并使用它。

于 2012-12-01T03:37:30.870 回答
0

如果您在 xib 中使用 Tableview ..所以您想在文件所有者中提供 tableview 的数据源和委托连接..

于 2011-07-15T05:08:21.357 回答
0

既然你说它tableView:accessoryButtonTappedForRowWithIndexPath:被调用,我们知道你的 tableView 的委托属性设置正确。所以tableView:didSelectRowAtIndexPath:也应该被调用。如果它没有被调用,我最好的猜测是你在方法签名的某个地方有一个错字。将此方法签名复制并粘贴到您的代码中,以确保您没有意外省略“tableView:”部分或出现大写错误。

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

编辑:次要假设:在您定义自定义单元格的 .xib 中,确保选中“启用用户交互”。

于 2011-07-15T05:44:43.860 回答