Arun Kumar
Arun Kumar

Reputation: 798

passing the value from one view to other view in UITabBarController

I am novice in iOS.. so I have question. I have 2 views in a UITabBar. one is registration and second one is details.

I want to pass textfields data from registration view to details view. registrations view containing textfields .

how can I do it??

Thankss

Upvotes: 0

Views: 860

Answers (2)

Jeff Loughlin
Jeff Loughlin

Reputation: 4174

I usually use the App Delegate for things that need to be passed around like that.

Create an instance variable in your app delegate to store the value you want to share, e.g.:

NSString *name;

In your Registration view, store the value into the instance variable in your app delegate:

AppDelegate *ad = (AppDelegate *)[[UIApplication sharedApplication] delegate];
ad.name = self.nameField.text;

Then in your Details view you can access it by something like:

AppDelegate *ad = (AppDelegate *)[[UIApplication sharedApplication] delegate];
self.nameLabel.text = ad.name;

Alternatively, you could keep a pointer to your Registration view in your app delegate and then just reference that from your Details view and access the text fields directly.

Upvotes: 2

nzs
nzs

Reputation: 3252

Options:

  1. Use global variable: SO answer
  2. Use delegation pattern: SO answer
  3. Use notification infrastructure: article
  4. Persist the value in app's userdefault storage, then read when you need : SO answer

Upvotes: 5

Related Questions