Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
macOS & iOS Developer Playground
iOS Development
Value passing problem from once class to another
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="sagarshivam" data-source="post: 1290913" data-attributes="member: 203583"><p>Dear All</p><p></p><p>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.</p><p></p><p>But When the same procedure I follow for SubTable.m (where Nsarray timevalue is defined), a null array is assigned in SubTable.m</p><p></p><p>Codes are :</p><p></p><p>SimpleTableViewAppDelegate.m</p><p></p><p>[CODE]</p><p>- (void)applicationDidFinishLaunching:(UIApplication *)application {</p><p> </p><p> RootViewController *rootViewController = [[RootViewController1 alloc] initWithStyle:UITableViewStylePlain];</p><p> window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];</p><p> </p><p>SubTable *sub = [[SubTable alloc] initWithStyle:UITableViewStylePlain];</p><p>NSArray *timeZones = [NSTimeZone knownTimeZoneNames];</p><p></p><p>rootViewController.timeZoneNames = [timeZones sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];</p><p> </p><p> </p><p> NSArray *test_array = [[NSArray alloc] initWithArray:timeZones];</p><p> sub.timevalue = [test_array copy];</p><p> //NSLog(@"count is %d", [sub.timevalue count]);</p><p> </p><p>UINavigationController *aNavigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];</p><p> self.navigationController = aNavigationController;</p><p> [aNavigationController release];</p><p> [rootViewController release];</p><p> [window addSubview:[navigationController view]];</p><p> [window makeKeyAndVisible];</p><p>}</p><p></p><p>[/CODE]</p><p></p><p>RootViewController.h is like:</p><p></p><p>[CODE]</p><p>@interface RootViewController : UITableViewController {</p><p> NSArray *timeZoneNames;</p><p>}</p><p></p><p>@property (nonatomic, retain) NSArray *timeZoneNames;</p><p></p><p>@end</p><p>[/CODE]</p><p></p><p>And inside RootViewController.m , </p><p>[CODE]</p><p>- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {</p><p> NSLog(@"timezonesname count is %d", [timeZoneNames count]);</p><p> return [timeZoneNames count];</p><p>}</p><p>[/CODE]</p><p></p><p>In above case, correct value is getting displayed.</p><p></p><p>While </p><p> SUbTable.h looks like:</p><p></p><p>[CODE]</p><p>@interface SubTable: UITableViewController {</p><p> </p><p> NSArray *timevalue;</p><p></p><p>}</p><p>@property (nonatomic ,retain) NSArray *timevalue;</p><p>@end[/CODE]</p><p></p><p>and Inside SUbTable.m</p><p>[CODE]</p><p>- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {</p><p> NSLog(@"timevalue count is %d", [timevalue count]);</p><p> return [timevalue count];</p><p>}[/CODE]</p><p></p><p>And here value displayed is always 0.</p><p></p><p>Where exactly I am making the mistake? What should I do so that timevalue can be assigned in the same way timeZoneNames is assigned.</p></blockquote><p></p>
[QUOTE="sagarshivam, post: 1290913, member: 203583"] 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]; } [/CODE] RootViewController.h is like: [CODE] @interface RootViewController : UITableViewController { NSArray *timeZoneNames; } @property (nonatomic, retain) NSArray *timeZoneNames; @end [/CODE] And inside RootViewController.m , [CODE] - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { NSLog(@"timezonesname count is %d", [timeZoneNames count]); return [timeZoneNames count]; } [/CODE] 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[/CODE] and Inside SUbTable.m [CODE] - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { NSLog(@"timevalue count is %d", [timevalue count]); return [timevalue count]; }[/CODE] 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]
Verification
Post reply
Forums
macOS & iOS Developer Playground
iOS Development
Value passing problem from once class to another
Top