【问题标题】:One segue identifier used between two UIViewControllers for multiple UITableView cell data transfer?在两个 UIViewControllers 之间使用一个 segue 标识符用于多个 UITableView 单元格数据传输?
【发布时间】:2013-04-29 02:50:56
【问题描述】:

在这种情况下,我将以下值分配给stringToDisplay,并希望将它们发送给SegViewController,它也保留stringToDisplay。我需要在这里使用cell.textLabel.text 和isEqualToString: @"Fire House Gallery 吗?我会在这里使用indexPath 或UITableViewCell 吗?

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
  SegViewController *seg = segue.destinationViewController;
  seg.delegate = (id)self;

  if ("......" isEqualToString: @"Firehouse Gallery"])
  {
      seg.stringToDisplay = @"Firehouse Gallery";
  }
  else
  {
      seg.stringToDisplay = @"Frog Hollow Craft Center";
  }
}

谢谢你, 格雷格

【问题讨论】:

    标签: uitableview xcode4


    【解决方案1】:

    简短回答:

    您不应该从表格视图单元格中获取数据,因为它们是您的视图。你应该从你的模型中“导出数据”。

    更长的答案:

    决定如何配置你的 segue 取决于你如何称呼它:

    如果您在代码中调用它(使用performSegueWithIdentifier:sender),则将您的字符串作为“发送者”传递给您的方法调用。

    如果您在情节提要中设置了转场,那么您应该为每种可能性使用不同的转场,并检查转场标识符以确定您应该传递哪个字符串。

    【讨论】:

      【解决方案2】:

      我找到了我正在寻找的答案。我现在在两个 UIView 控制器之间有一个 segue 链接,segue identifier 称为 @"seg"。对于名为 Radio Bean 的地方,我在按下“Radio Bean”单元格时使用以下内容:

      if ([cell.textLabel.text isEqualToString: @"Radio Bean"])
      {
           self.stringToDisplay = @"Radio Bean";
           [self performSegueWithIdentifier:@"seg" sender:self];
      }
      

      然后,在prepareForSegue 中,我没有指定segue identifier,而是使用以下内容:

      - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
      {
         SegViewController *seg = segue.destinationViewController;
         seg.delegate = (id)self;
      
         if ([self.stringToDisplay isEqualToString: @"Radio Bean"])
         {
             seg.stringToDisplay = @"Radio Bean";
         }
      }
      

      这成功地将“Radio Bean”传递给下一个UIViewcontroller,并且我可以仅使用一个segue链接来包含多个位置选项,因此不需要多个链接。

      【讨论】:

        猜你喜欢
        • 2013-04-30
        • 2012-12-27
        • 1970-01-01
        • 1970-01-01
        • 2011-04-28
        • 2018-02-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多