【问题标题】:One TableViewController with 2 sections linking to 1 DetailView?一个 TableViewController 有 2 个部分链接到 1 个 DetailView?
【发布时间】:2014-02-06 01:41:30
【问题描述】:

所以在我的项目中,我有一个 HistoryTableViewController,其中包含 2 个部分。一个部分是 PeopleYouOwe,另一部分是一组 PeopleWhoOweYou。我如何能够连接这个 tableviewcontroller 并将其链接到一个详细视图,该视图将根据我的部分显示不同的数据?

【问题讨论】:

    标签: objective-c xcode core-data


    【解决方案1】:

    使用 prepareForSegue 尝试以下方法 -
    创建名为 myTableView

    的 tableView 出口
    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
     // Get the new view controller using [segue destinationViewController].
     // Pass the selected object to the new view controller.
    
     NSIndexPath *path = [self.myTableView indexPathForSelectedRow];
    
     if (path.section == 0)
     {
         if ([segue.identifier isEqualToString:@"PeopleYouOwe"])
         {
             PeopleYouOwe *peopleYouOweVC = segue.destinationViewController;
             // you can get data of cell as array[path.row]
         }
     }
     else if (path.section == 1)
     {
         if ([segue.identifier isEqualToString:@"PeopleWhoOweYou"])
         {
             PeopleWhoOweYou *peopleWhoOweYou = segue.destinationViewController;
              // you can get data of cell as array[path.row]
         }
    
     }
    
    
    }     
    

    【讨论】:

      【解决方案2】:

      您可以像这样使用 UITableViews 提供的委托方法:

      - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
      {
          NSInteger row = indexPath.row;
          NSInteger section = indexPath.section;
          if(section == 0) // example
          {
              // do whatever
          }
          else if (section == 1)
          {
              // do something else
          }
      }
      

      如果这不是您要查找的内容,您将需要提供更多详细信息,最好是一些代码来显示您已经拥有的内容。你的问题很模糊。

      【讨论】:

      • 我的 didSelectRowAtIndexPath 方法搞砸了,所以我想我会使用 -(void)prepareForSegue。你的代码还能在那个方法中应用吗?
      【解决方案3】:

      如果你更喜欢 prepareForSegue,你可以使用类似的东西:

      NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
      

      然后根据部分和行采取行动。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-05-17
        • 1970-01-01
        • 2019-03-30
        • 1970-01-01
        • 2013-05-06
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多