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