New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
iOS Development Discussion on developing apps for the iOS platform.

Value passing problem from once class to another


Post Reply New Thread Subscribe

 
Thread Tools
sagarshivam

 
Member Since: Jun 03, 2011
Posts: 54
sagarshivam is on a distinguished road

sagarshivam is offline
Dear All

I am able to assign values to NSarray timeZoneNames defined in RootViewController.m from SimpleTableViewAppDelegate.m and then I can use 'timeZoneNames' inside RootViewController.m perfectly.

But When the same procedure I follow for SubTable.m (where Nsarray timevalue is defined), a null array is assigned in SubTable.m

Codes are :

SimpleTableViewAppDelegate.m

Code:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
	
	RootViewController *rootViewController = [[RootViewController1 alloc] initWithStyle:UITableViewStylePlain];
	window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
	
SubTable *sub = [[SubTable alloc] initWithStyle:UITableViewStylePlain];
NSArray *timeZones = [NSTimeZone knownTimeZoneNames];

rootViewController.timeZoneNames = [timeZones sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
	
	
  NSArray *test_array = [[NSArray alloc] initWithArray:timeZones];
  sub.timevalue = [test_array copy];
	//NSLog(@"count is %d", [sub.timevalue count]);
	
UINavigationController *aNavigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
	self.navigationController = aNavigationController;
	[aNavigationController release];
	[rootViewController release];
	[window addSubview:[navigationController view]];
	[window makeKeyAndVisible];
}
RootViewController.h is like:

Code:
@interface RootViewController : UITableViewController {
	NSArray *timeZoneNames;
}

@property (nonatomic, retain) NSArray *timeZoneNames;

@end
And inside RootViewController.m ,
Code:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
	NSLog(@"timezonesname count is %d", [timeZoneNames count]);
	return [timeZoneNames count];
}
In above case, correct value is getting displayed.

While
SUbTable.h looks like:

Code:
@interface SubTable: UITableViewController {
	
	NSArray *timevalue;

}
@property (nonatomic ,retain) NSArray *timevalue;
@end
and Inside SUbTable.m
Code:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
	NSLog(@"timevalue count is  %d", [timevalue count]);
    return [timevalue count];
}
And here value displayed is always 0.

Where exactly I am making the mistake? What should I do so that timevalue can be assigned in the same way timeZoneNames is assigned.
QUOTE Thanks
Nethfel

 
Member Since: Feb 25, 2009
Posts: 2,102
Nethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of light
Mac Specs: Late 2013 rMBP, i7, 750m gpu, OSX versions 10.9.3, 10.10

Nethfel is offline
Ok, I must be missing something because I'm tired, but I see where you instantiate the SUbTable object, but I don't see where you're actually pushing it onto the navigation stack to become visible.

My guess is (and it's just a guess), and I can't verify this because I don't see where you're pushing it on - you're re-instantiating it (probably inside of rootViewController?) and pushing it on and that new instance you're not setting the timevalue ivar for that new instance (since multiple instances of a single class won't share instance variables, instance variables are unique for each instance of a class)...

My Macs: Late 2013 rMBP w/ 750m; Mac mini G4, 1.25 GHz, 512m ram (server); Late 2011 11" MBA, 1.8GHz i7, 4Gig Ram, 256Gig SSD, HD3000; Powerbook 12" G4 1.33GHz running Debian as a server; Apple TV (1080p version)
QUOTE Thanks
sagarshivam

 
Member Since: Jun 03, 2011
Posts: 54
sagarshivam is on a distinguished road

sagarshivam is offline
Hi

I have not re-instantiated the SUbTable object. It has been instantiated only once and that in application delegate class.

Moreover I just tried making a replica of RootViewController (in form of SubTable) but output is not coming as expected.

Is it something that I should instantiate the SubTable classs object inside RootViewController.m or is it something that scope of object is valid only in current view?? [ Subtable is the next view(It comes when any cell of RootViewController is tapped)].
QUOTE Thanks
Nethfel

 
Member Since: Feb 25, 2009
Posts: 2,102
Nethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of light
Mac Specs: Late 2013 rMBP, i7, 750m gpu, OSX versions 10.9.3, 10.10

Nethfel is offline
Well, where's the code that actually pushes the sub table view controller? How are you referencing it from the app delegate? I see your base instantiation, but from the scope, it will only exist in the method:

Code:
 - (void)applicationDidFinishLaunching:(UIApplication *)application
- no where do you pass the sub view controller to your root view.

Usually when using a nav controller, when you need to push a new view, it's instantiated and has its ivars set just before pushing onto the view controller, not at the point of the app delegate. The only view controller that should be instantiated at the app delegate at launch is the root view controller and any controllers the root view controller requires to operate (ie: navigation view controller as the root, and then its initial view controller) - there are only rare times where you'd need more then those required view controllers (like if you're outputting to an external screen through your app).

Unfortunately, there isn't enough code shown to fully see how you are pushing your sub view onto the stack and how you think you're accessing it, which would seem at this point you're not accessing at all (btw - with what you've shown, you leak that view controller)...

My Macs: Late 2013 rMBP w/ 750m; Mac mini G4, 1.25 GHz, 512m ram (server); Late 2011 11" MBA, 1.8GHz i7, 4Gig Ram, 256Gig SSD, HD3000; Powerbook 12" G4 1.33GHz running Debian as a server; Apple TV (1080p version)
QUOTE Thanks

Post Reply New Thread Subscribe


« Key- Value Table help required | Button Looping and me! »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
Strange iweb problem Anyuta Web Design and Hosting 0 09-27-2010 12:46 PM
2009 MBP - Possible Trackpad Problem tricky10 Apple Notebooks 6 09-09-2010 07:01 AM
skype problem kingkolmanmac OS X - Apps and Games 0 09-01-2010 10:28 AM
iPhone onscreen volume control problem smuggerific iOS and Apps 1 04-19-2010 10:18 AM
Possible faulty CPU thermometer, common problem? dyaballikl Apple Notebooks 6 11-16-2008 12:21 AM

All times are GMT -4. The time now is 08:09 AM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?