简体   繁体   English

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

[英]How to call/pass an array value from a table cell into a view?

As novice/beginner programmer for iOS, I unfortunately have come across a roadblock that I would like some assistance with. 作为iOS的新手/初学者程序员,很不幸,我遇到了需要帮助的障碍。 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". 然后,此单元格将填充从数组传递的信息(两个标签titleLabel和timeLabel,以及由整数typeOfCell表示的单元格“类型”),从而允许数组生成多个单元格,而仅使用单个原型单元“模板”。 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. 非常感谢您提供任何反馈意见,谢谢您的时间和答复。

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. 那就是UINavigationController应该做的。 Here is a link UINavigationController apple documentation link . 这是一个链接UINavigationController苹果文档链接

Hope this is what your looking for. 希望这是您想要的。

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. 如果要将值从表单元格传递到被调用的视图,则可以在视图中创建与要传递的值相对应的成员变量,对其进行合成并在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 */
   }

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

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