目标-c如何从popToRootViewController类获取数据,我在该类中有Text字段,我希望在屏幕弹出时使用该textfield文本

Prashant Tukadiya

我已经UITextField在这个类我想要那个文本框的文本时,屏幕上弹出

我有try属性来访问textfield的值,但它返回nil

AddItem *item = [AddItem viewController];

NSLog(@"%@",item.txtField.text);

添加项目是我的班级,将在单击时显示,显示为零

Duyen-Hoa

在调用popToRoot之前,可以发送文本字段为object =内容的Notification。然后在根viewcontroller中,将其作为观察者添加到此通知中。

另一种方法:在第3个控制器中设置对根控制器的引用。在根控制器中添加一个方法“ closeToMe:”,该方法调用PopToRoot。然后,从第3个控制器中,当您想“弹出至根目录”时,使用文本字段的内容调用[referenceToA closeToMe:]。

这是代码段:

RootViewController:

//to be simple, declare this in header to facilite access to this function
-(void)closeToMe:(NSString*)newContent {
     //do your work with newContent

    //then, call poptoRoot (in main thread)
    dispatch_async(dispatch_get_main_queue(),nil, {
        //navigation.PopToCOntroller(self)
    });
}


3rdController):

@property (nonatomic) RootViewController; //set it when you show the pop-up from RootViewController

-(IBAction)close:(id)sender {
    if (self.controller && [self.controller respondsTo:@sel(closeToMe:)]) {
        [self.controller closeToMe:myTextField.text];
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

Related 相关文章

热门标签

归档