如何将数组值从表单元格调用/传递到视图中?

发布于 2025-01-06 04:10:54 字数 288 浏览 6 评论 0原文

作为 iOS 新手/初学者程序员,我不幸遇到了一个障碍,我需要一些帮助。使用故事板,我创建了一个具有单个原型单元的表格视图。然后,该单元格将填充从数组传递的信息(两个标签,titleLabel 和 timeLabel,以及由整数 typeOfCell 表示的单元格“类型”),从而允许数组生成多个单元格,同时仅使用单个原型单元“模板”。 我想要完成的是允许用户从表格中选择一个单元格,然后出现一个视图来显示该单元格中的信息。由于我是初学者,请给出明确的信息如果您选择回答此问题,请提供说明。非常感谢任何反馈,感谢您的时间和答复。

As novice/beginner programmer for iOS, I unfortunately have come across a roadblock that I would like some assistance with. Using storyboards, I have created a table view that has a single prototype cell. This cell then gets populated with information that has been passed from an array (two labels, titleLabel and timeLabel, as well as a "type" of cell that is represented by an integer, typeOfCell), allowing multiple cells to be generated by the array, while only using the single prototype cell "template". What I am trying to accomplish is to allow the user to select a cell from the table, and then have a view come up that displays the information in that cell. Since I am a beginner, please give explicit instructions should you choose to answer this question. Any feedback is greatly appreciated, thank you for your time and answers.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苯莒 2025-01-13 04:10:54

因此,如果我正确理解了这一点,您单击表格中的一个单元格,您想移动到不同的视图吗?这就是 UINavigationController 应该做的事情。这是一个链接 UINavigationController 苹果文档链接。

希望这就是您所寻找的。

So if I get this correctly, you click on a cell in the table, you want to move to different view? That is what is the UINavigationController is supposed to do. Here is a link UINavigationController apple documentation link.

Hope this is what your looking for.

倾城°AllureLove 2025-01-13 04:10:54

如果您打算将值从表格单元格传递到调用的视图,那么您可以在视图中创建与要传递的值相对应的成员变量,对其进行综合并将值传递到 didSelectRow 方法。

- (void)tableView:(UITableView *)tableView
    didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

       CustomTableCell *lCell = (CustomTableCell*)[tableView cellForRowAtIndexPath:indexPath];

       if(indexPath.row == x) //x being the row required 
       {
            NewViewController *lNewVC = [[NewViewController alloc] init]; //This class will have titleLabel, timeLabel and cellType as member vars
            lNewVC.titleLabel = cell.titleLabel;       
            lNewVC.timeLabel = cell.timeLabel;
            lNewVC.cellType = cell.typeOfCell;

            [self.navigationController pushViewController:lNewVC animated:YES];
       }
       else
       /* similar code for other rows */
   }

If you are looking at passing the values from the tablecell to the view that is called, then you can create member variables in the view corresponding to the values to be passed, synthesize it and pass the values in the didSelectRow method.

- (void)tableView:(UITableView *)tableView
    didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

       CustomTableCell *lCell = (CustomTableCell*)[tableView cellForRowAtIndexPath:indexPath];

       if(indexPath.row == x) //x being the row required 
       {
            NewViewController *lNewVC = [[NewViewController alloc] init]; //This class will have titleLabel, timeLabel and cellType as member vars
            lNewVC.titleLabel = cell.titleLabel;       
            lNewVC.timeLabel = cell.timeLabel;
            lNewVC.cellType = cell.typeOfCell;

            [self.navigationController pushViewController:lNewVC animated:YES];
       }
       else
       /* similar code for other rows */
   }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文