我想获取自定义创建的 uitableviewcell 的父视图。我尝试使用 self superview 来获取父 tableview ,但它没有用。
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization cod
UITableView *tableView = (UITableView *)[self superview];
NSIndexPath *indexPath = [tableView indexPathForCell:self];
NSLog(@"%d %d", indexPath.section, indexPath.row);
...
}
Nslog 输出的值完全为 0。
@jrturton 给出了 self superview 不能引用其父视图的原因。但下一个问题是我想在单元格初始时获取 indexPath。