开发者

Sending Variables Between iPhone Controllers

I am currently in the process of switching from Android to the iPhone SDK. I have a TableView where the user selects an item. I am having trouble passing data between controllers. Is there an equivalent to the Android's startActivityForResult or putting extra's into Intents? Like so ..开发者_StackOverflow社区.

Intent i = new Intent(this, Foo.class);
i.putExtra("Foo", foo);


Take this in .h file in ParentViewController

NSString *strABC;

Make below function in ParentViewController

-(void)setString:(NSString *)strEntered{
    strABC=strEntered;
}

Now In Post view controller do like this:

ParentViewController *objSecond = [[ParentViewController] initwithNibName:@"parentView.xib" bundle:nil];

[objSecond setString:@"Comment Controller"];
[self.navigationController pushViewController:objSecond animated:YES];
[objSecond release];

Now, In secondViewController viewWillAppear Method write this.

-(void)viewWillAppear:(BOOL)animated{
      lblUserInput.text = strABC;
}

Please check spelling mistakes as I hand written this. Hope this help.

If you are not using navigationContoller then you can do something like this.

SecondViewControler *objSecond = [[SecondViewController] initwithNibName:@"secondview.xib" bundle:nil];
[objSecond setUserInput:txtUserInput.text];
[objSecond viewWillAppear:YES];
[self.view addSubview:objSecond];
[objSecond release];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜