繁体   English   中英

外部笔尖中的表视图单元格。 故事板

[英]Table View Cell in external nib. Storyboards

因此,我一直在情节提要中构建表视图,并使用自定义UITableViewCell创建了一个外部Nib文件。 一切都很好。 但是,表格视图单元格上有一个按钮,我想通过segue连接到情节提要中的视图。 现在我对这一切仍然很陌生,那么如何将自定义单元上的按钮连接到情节提要中的视图控制器? 我完全犯错了吗? 如果是这样,我将如何快速,轻松地重组项目? 如果您能提供一点解释,我将不胜感激。

谢谢你的帮助,
问候,
麦克风

可以使用故事板在故事板中的UITableViewCell内设置按钮。 我以前做过类似的事情。 因此,这是一个解决方案;

  • 在UITableView单元内创建原型单元,并向其中添加一个UIButton。
  • 从按钮到新的视图控制器创建序列,然后选择模式或按钮。

现在,在UITableViewData数据源cellForRowAtIndexPath;中。

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if(!cell){
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    UIButton *button = ((UIButton*)[cell.contentView.subviews objectAtIndex:0])
    button.tag = indexPath.row;
    cell.textLabel.text = @"Hello Text"
    ;
    return cell;
}

现在,单击按钮时,将调用prepareForSegue:。

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if([segue.identifier isEqualToString:@"identifier"]){
        UIButton *button = (UIButton*)sender;
        NewViewController *viewController = [segue destinationViewController];
       if(button.tag == 1)
          viewController.someobject = ...
       else 
          viewController.somobject = ...
    }
}

那应该起作用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM