NSDeveloper
NSDeveloper

Reputation: 1

iOS passing data between two Views

I'm using two views (view controllers VC1 and VC2) and passing data from VC1 to VC2 I stored the values for two variables in VC2

  //VC1 store obj to VC2
self.VC2.twtid=ide;
self.VC2.urlString=[[NSURL alloc]  initWithString:vurl];

I received the values after VC2 was shown. My problem is when I click in any cell in VC1 for the second time. When I navigate back to VC1(tableview) again and tried to select cell, the values aren't stored again.

  //VC.h I declare the two var 
@property(strong, nonatomic) NSNumber *twtid;

@property(strong, nonatomic) NSURL *urlString;

note: I didn't use prepareForSegue.without Segue!!

Upvotes: 0

Views: 76

Answers (3)

Allen
Allen

Reputation: 6882

You don't need to store the VC2 as VC1's property, just init it every time.

Upvotes: 0

Himanshu padia
Himanshu padia

Reputation: 7712

ViewController2 *VC2 = (ViewController2 *)[self.storyboard instantiateViewControllerWithIdentifier:@"ViewController2"];
VC2.url = urlString; // use your variable over here, this is just and example
[self presentViewController:VC2 animated:YES completion:^{         }];
[self.navigationController pushViewController:VC2 animated:YES];

user presentViewController or pushViewController as per your requirement

Upvotes: 0

Karthik Mandava
Karthik Mandava

Reputation: 517

Use global variables othereise use Segue methods.

Upvotes: 1

Related Questions