简体   繁体   English

从表格单元格中的文本从一个View控制器获取到另一个View控制器

[英]Getting text from table cell from one View controller to another View controller

having trouble getting a cell that is tapped and has a checkmark to send the cell text to another View Controller 无法获取被点击的单元格并带有选中标记以将单元格文本发送到另一个View Controller时遇到问题

here is my code for didSelectRowAtIndexPath 这是我的didSelectRowAtIndexPath代码

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

    if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
        cell.accessoryType = UITableViewCellAccessoryNone;

    }
    else {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }

}

I also have this inside a IBAction when the View Controller is dismissed: 当视图控制器被关闭时,我也可以在IBAction中使用它:

[self dismissViewControllerAnimated:YES completion:nil];

((FSPhotoProcessViewController *)self.presentingViewController).categoryResult.text = cell.textLabel.text;

When i press the button the app crashes, but if i comment out the presentingViewController line out, then its fine. 当我按下按钮时,应用程序崩溃,但是如果我注释掉presentingViewController行,那么它就可以了。

[UITabBarController categoryResult]: unrecognized selector sent to instance 

wondering how to get the tapped cell text to another view 想知道如何将点击的单元格文本显示到另一个视图

thanks. 谢谢。

Do you need to dismiss the view controller? 您需要解雇视图控制器吗? You could just load the other one on top of it and then dismiss the new view controller to come back to where you are. 您可以将另一个加载在其顶部,然后关闭新的视图控制器以返回您所在的位置。

I had a similar problem and dismissing the main view controller was the issue. 我遇到了类似的问题,因此将主视图控制器排除在外了。

You need to pass texts as NSStrings(create a property in your destination view controller) and then in the viewWillAppear part of destination view controller you need to set UI parts from that NSString property. 您需要将文本作为NSStrings传递(在目标视图控制器中创建属性),然后在目标视图控制器的viewWillAppear部分中,您需要从该NSString属性设置UI部分。 This error occurs before you destination view controller's UI parts are not implemented until segue call. 在调用segue之前,未实现目标视图控制器的UI部件之前,会发生此错误。 Therefore you want to pass NSString to UI objects text property but you UI object is not created in the memory. 因此,您想将NSString传递给UI对象的text属性,但不会在内存中创建UI对象。

Example: 例:

((FSPhotoProcessViewController *)self.presentingViewController).myStringProperty = cell.textLabel.text;    

Note: You can also pass numbers,arrays, dictionaries and your custom objects(not UI related). 注意:您还可以传递数字,数组,字典和自定义对象(与UI不相关)。

暂无
暂无

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

相关问题 从一个视图 controller 到另一个视图显示表格视图单元格的问题 - Issues displaying a table view cell from one view controller to another 如何将信息从一个视图控制器中的表视图单元传递到另一视图控制器? - How do I pass information from a table view cell in one view controller to another view controller? 从一个视图控制器获取数据到另一个 - getting data from one view controller to another 从另一个视图控制器以编程方式选择一个表视图单元格 - Selecting a Table View Cell programmatically from another view controller 将单元信息从一个视图控制器发送到另一个Swift和Parse - Sending cell info from one view controller to another Swift and Parse 将自定义单元格从一个视图控制器传递到另一个 - passing custom cell from one view controller to another 使用来自单独的表视图控制器的选定单元格填充文本字段 - Populating a Text Field with a Selected Cell from a Separate Table View Controller 如何从一个视图 controller 设置结构变量数据并从另一个视图 controller 获取相同的值 - How to set Struct Variable data from one view controller And Getting same value from Another view controller 如何在xcode中从一个表视图控制器导航到另一个表视图控制器 - how to navigate from one table view controller to another table view controller in xcode 将json ID从一个表视图控制器传递到Swift 3中的另一个表视图控制器 - pass json id from one table view controller into another table view controller in swift 3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM