【问题标题】:Pushing the ViewController in customize Tableview Cell在自定义 Tableview Cell 中推送 ViewController
【发布时间】:2014-08-26 08:30:08
【问题描述】:

我正在使用使用自定义表格单元格并在该单元格中有一个按钮操作,点击它应该会将我带到另一个 ViewController,我在按钮操作中使用此代码但它不起作用:

 PhotoViewController *photo = [[PhotoViewController alloc]initWithNibName:@"PhotoViewController" bundle:nil];
  [self.navigationController pushViewController:photo animated:YES];

【问题讨论】:

  • 您是否在您的 IBAction 方法上应用了调试器?该方法是否在您的水龙头上调用?
  • @iProgrammer:不,我不知道你的意思,我已经为那个按钮创建了一个 IB 操作方法,并在该方法中传递了上述代码
  • @user3807171 不确定您的评论是什么意思 - 我只是让您的问题更清楚,以便其他人帮助您。
  • 在您的 IBAction 回调上应用断点并检查 self.navigationController 是否有参考?
  • 得到了解决方案 :-) 谢谢创建 IBOutlet 并在 cellForRowAtIndexPath 方法中声明:cell.photoAlbum.tag = indexPath.row; [cell.photoAlbum addTarget:self action:@selector(photoAblumClicked:) forControlEvents:UIControlEventTouchUpInside]; 并且在 photoAblumClicked 中调用了上面的代码,它工作正常谢谢:-)

标签: ios xcode uitableview uinavigationcontroller


【解决方案1】:

得到解决方案 :-) 感谢创建 IBOutlet 并在 cellForRowAtIndexPath 方法中声明:

 cell.photoAlbum.tag = indexPath.row; [cell.photoAlbum addTarget:self 
action:@selector(photoAblumClicked:) forControlEvents:UIControlEventTouchUpInside]; 

并且在 photoAblumClicked 中调用了上面的代码,它工作正常谢谢 :-)

【讨论】:

    【解决方案2】:
    - (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];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-21
      • 1970-01-01
      • 1970-01-01
      • 2023-03-15
      相关资源
      最近更新 更多