我正在通過uitableviewcell的子類自定義表格視圖單元格。那麼,如何在單元格被觸摸時從這個視圖控制器轉移到另一個視圖控制器?謝謝。如何在自定義的tableViewController中轉移到另一個viewController?
看來,在執行tableview: didSelectRowAtIndexPath:
不起作用。這裏是我的代碼:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
SecondViewController *anotherViewController = [[SecondViewController alloc] init];
[[self navigationController] pushViewController:anotherViewController animated:YES];
}
這是我得到了什麼,當我按下行的表視圖:
這是myCell.m(我的自定義單元格)的代碼:
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.mainLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, 180, 30)];
self.mainLabel.font = [UIFont systemFontOfSize:14.0];
[self.contentView addSubview:self.mainLabel];
self.mainButton = [UIButton buttonWithType:UIButtonTypeSystem];
self.mainButton.frame = CGRectMake(190, 5, 100, 30);
[self.mainButton addTarget:self action:@selector(logButton:) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:self.mainButton];
}
return self;
}
- (void)logButton:(UIButton *)sender{
NSLog(@"index path: %ld", (long)sender.tag);
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
}
什麼是您的自定義表格視圖單元格的控件???這些表格視圖單元格內的那些控件是否需要觸摸事件? –
具體而言_what_不起作用?感謝您發佈您的代碼,這有幫助,但是當您選擇表格視圖單元格時會發生什麼? –