将核心数据实体属性从ViewController A传递到B [英] Pass Core Data Entity Attribute From ViewController A to B

查看:58
本文介绍了将核心数据实体属性从ViewController A传递到B的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对核心数据有小的疑问。
因为它可以正常工作,所以我将跳过代码。我只需要知道在
prepareForSeague方法内可以做什么。

I have small problem with Core Data. I will skip the code because it's working fine. I just need to know what to do inside prepareForSeague method.

应用程序有2个视图-ViewControllerA和TableViewControllerB。
在TableViewControllerB中,我使用带有单元格标识符:customCell的自定义单元格设置了表格视图。
我按下按钮ADD,它显示有2行的Alert视图。警报视图向实体添加2个属性,这些属性显示在表单元格中。
实体称为SOMEentity,而属性是名称(NSString)和值(也包括NSString)。

App has 2 Views - ViewControllerA and TableViewControllerB. In TableViewControllerB I've set up table view with custom cell with cell identifier: customCell. I press button ADD and it shows Alert view with 2 rows. Alert View adds 2 Attributes to entity and these attributes are displayed in table cell. Entity is called SOMEentity while Attributes are name (NSString) and value (NSString also).

视图控制器A具有两个textFields:TextFieldA和TextFieldB,一个按钮计算并标记为calculateLabel。
的计算按钮只是从textFields中添加值。

View controller A has two textFields: TextFieldA and TextFieldB, a button calculate and label called calculateLabel. Calculate button simply adds values from textFields.

现在我要执行此操作-单击单元格将在TextFieldA中显示属性值。

Now I want to do this - clicking on cell will display Attribute Value in TextFieldA.

我必须在里面做什么

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender;
{
if ([[segue identifier] isEqualToString:@"FromViewBToViewA"]) {
}
}

此外,我是否必须在ViewControllerA的viewDidLoad方法内部编写某些内容?
所有字符串和标签都具有非原子性强属性。

Also, do I have to write something inside viewDidLoad method in ViewControllerA? all strings and labels have nonatomic, strong properties.

谢谢!

推荐答案

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender;
{
    if ([[segue identifier] isEqualToString:@"FromViewBToViewA"]) {
        ViewControllerA * dest = (ViewControllerA*)segue.destinationViewController;
        dest.property1 = @"Some property value";
        dest.property2 = @"Some property value";
    }
}

获取目标控制器的强制转换并将其传递给期望的对象价值观。然后在目标控制器中。确保在ViewControllerA的标头中包含property1和property2作为属性

Grab the destination controller cast it and pass in the expected values. Then in your destination controller. Make sure you include property1 and property2 as properties in the header of ViewControllerA

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:YES];
    //Set your text view values with your configured properties from the segue.
} 

这篇关于将核心数据实体属性从ViewController A传递到B的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆