我正在使用自定义表格单元格,并在该单元格中有一个按钮操作,并点击它应该带我到另一个ViewController,我在按钮操作中使用此代码,但它没有工作:
PhotoViewController *photo = [[PhotoViewController alloc]initWithNibName:@"PhotoViewController" bundle:nil];
[self.navigationController pushViewController:photo animated:YES];
答案 0 :(得分:1)
得到了解决方案:-) thanks创建了IBOutlet并在cellForRowAtIndexPath方法中声明:
cell.photoAlbum.tag = indexPath.row; [cell.photoAlbum addTarget:self
action:@selector(photoAblumClicked:) forControlEvents:UIControlEventTouchUpInside];
并在photoAblumClicked中调用上面的代码,它的工作正常,谢谢: - )
答案 1 :(得分:0)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *tableIdentifier = @"StaticTableViewCell"; StaticTableViewCell *cell = (FriendTableViewCell *)[tableView dequeueReusableCellWithIdentifier:tableIdentifier]; if (cell == nil) { NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"StaticTableViewCell" owner:self options:nil]; cell = [nib objectAtIndex:0]; } cell.button.tag = indexPath.row; [cell.button addTarget:self action:@selector(PhotoAlb:) forControlEvents:UIControlEventTouchUpInside]; return cell; }
-(void)PhotoAlb:(id)sender
{
PhotoViewController *photo = [[PhotoViewController alloc]initWithNibName:@"PhotoViewController" bundle:nil];
[self.navigationController pushViewController:photo animated:YES];
}