iPhone Development - Using Data from another view
First view: consists of a textview(user input) & button(pressing on this button takes u to the second view)
Second View: consists of a label
i want the label t开发者_运维百科o display what the user wrote in the first view.
I think you are creating second view when buttonClick. Just pass the data of textView (textView.text
) to constructor of second view. Then you can set data to the label in viewDidLoad()
method.
Take this in .h file in SecondViewController
NSString *strUserInput;
Make below function in seconviewcontroller
-(void)setUserInput:(NSString *)strEntered{
strUserInput=strEntered;
}
Now In first view controller do like this:
SecondViewControler *objSecond = [[SecondViewController] initwithNibName:@"secondview.xib" bundle:nil];
[objSecond setUserInput:txtUserInput.text];
[self.navigationController pushViewController:objSecond animated:YES];
[objSecond release];
Now, In secondViewController viewWillAppear Method write this.
-(void)viewWillAppear:(BOOL)animated{
lblUserInput.text = strUserInput;
}
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];
精彩评论