gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 21:19:05 47 4
gpt4 key购买 nike

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

47 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com