Results 1 to 4 of 4
  1. #1


    Member Since
    Jun 03, 2011
    Posts
    54
    Value passing problem from once class to another
    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.

  2. #2


    Member Since
    Feb 25, 2009
    Posts
    2,112
    Specs:
    Late 2013 rMBP, i7, 750m gpu, OSX versions 10.9.3, 10.10
    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, 16Gig ram; 2013 Mac Pro 6 core w/ D700, 16Gig Ram; 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 Linux; Apple TV (1080p version)

  3. #3


    Member Since
    Jun 03, 2011
    Posts
    54
    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)].

  4. #4


    Member Since
    Feb 25, 2009
    Posts
    2,112
    Specs:
    Late 2013 rMBP, i7, 750m gpu, OSX versions 10.9.3, 10.10
    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, 16Gig ram; 2013 Mac Pro 6 core w/ D700, 16Gig Ram; 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 Linux; Apple TV (1080p version)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Mourning the Passing of iPod Classic
    By mars47 in forum iPod Hardware and Accessories
    Replies: 11
    Last Post: 09-17-2014, 07:04 PM
  2. Passing on my iMac to my wife
    By IWT in forum Apple Desktops
    Replies: 7
    Last Post: 02-08-2013, 06:15 PM
  3. Passing DHCP to Airport Extreme
    By Netdewt in forum Internet, Networking, and Wireless
    Replies: 1
    Last Post: 11-18-2010, 11:48 PM
  4. by-passing a password
    By Tom Hayes in forum Apple Notebooks
    Replies: 1
    Last Post: 11-27-2009, 10:29 AM
  5. AirTunes passing thru a Mac
    By Blastocyst in forum Internet, Networking, and Wireless
    Replies: 0
    Last Post: 04-24-2007, 02:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •