Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-05-2011, 06:32 PM   #1 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 67
Penicillin is on a distinguished road
Default How can I call the same ViewController from two TabBar items

Hi,
How can I call the same ViewController from two TabBar items?

I used:
PHP Code:
MyViewController *vc1 = [[MyViewController allocinitWithNib:@"MyViewController" bundle:nil];
MyViewController *vc2 = [[MyViewController allocinitWithNib:@"MyViewController" bundle:nil];

UITabBarController *tabs = [[UITabBarController allocinit];
[
tabs setViewControllers:[NSArray arrayWithObjects:vc1vc2nilanimated:NO]; 
But variables will be reset, I want to keep the variables.

My view controller contains TableView with listdata, I just want to show first three of them when I click one 2nd TabBar, but listdata variable is reset and become nil.

Any fix?
Thanks
Penicillin is offline   Reply With Quote
Old 09-06-2011, 12:02 PM   #2 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 196
phillipie99 is on a distinguished road
Default

Quote:
Originally Posted by Penicillin View Post
Hi,
How can I call the same ViewController from two TabBar items?

I used:
PHP Code:
MyViewController *vc1 = [[MyViewController allocinitWithNib:@"MyViewController" bundle:nil];
MyViewController *vc2 = [[MyViewController allocinitWithNib:@"MyViewController" bundle:nil];

UITabBarController *tabs = [[UITabBarController allocinit];
[
tabs setViewControllers:[NSArray arrayWithObjects:vc1vc2nilanimated:NO]; 
But variables will be reset, I want to keep the variables.

My view controller contains TableView with listdata, I just want to show first three of them when I click one 2nd TabBar, but listdata variable is reset and become nil.

Any fix?
Thanks
Try this
Code:
MyViewController *vc1 = [[MyViewController alloc] initWithNib:@"MyViewController" bundle:nil];


UITabBarController *tabs = [[UITabBarController alloc] init];
[tabs setViewControllers:[NSArray arrayWithObjects:vc1, vc1, nil] animated:NO];
__________________
My new app Catch The Coconut.
Website: PhilBystricanApps.com
phillipie99 is offline   Reply With Quote
Old 09-08-2011, 05:15 PM   #3 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 67
Penicillin is on a distinguished road
Default

Quote:
Originally Posted by phillipie99 View Post
Try this
Code:
MyViewController *vc1 = [[MyViewController alloc] initWithNib:@"MyViewController" bundle:nil];


UITabBarController *tabs = [[UITabBarController alloc] init];
[tabs setViewControllers:[NSArray arrayWithObjects:vc1, vc1, nil] animated:NO];
It didn't work that way, it's showing two tabs, but only one is working, the second one is inactive

I used singleton variable to solve it.
Penicillin is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 381
7 members and 374 guests
apatsufas, JackReidy, jeroenkeij, Sami Gh, tim0504, yomo710
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,671
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, JackReidy
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:50 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0