1

I am not sure why I keep getting this error, I do pass the userId from the profile view controller on a button click with a push:

TotalTabController *userTabView = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"userTabView"];
    userTabView.userProfileId = userId;

    NSLog(@"the user tota tab is %@", userId);
    userTabView.userProfileName = profileName;
    [self.navigationController pushViewController:userTabView animated:NO];

The NSLog prints out the correct userID, and then I have it added to the tab controller in the .h file like so:

@interface TotalTabController : UITabBarController {
    NSString *userProfileId, *userProfileName;
}

@property (nonatomic, retain) NSString *userProfileId;
@property (nonatomic, retain) NSString *userProfileName;

And in the .m file like so:

@synthesize userProfileId, userProfileName;

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSLog(@"the  tab loaded and is %@", userProfileId);
}

but the NSLog prints out null in the .m file...

Then I call it in one of the tab views .m file like so:

userProfileId = [(TotalTabController*)self.tabBarController userProfileId];

And then get this error:

The error is:

2014-05-17 11:49:04.667 Example[1108:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(
    0   CoreFoundation                      0x01e291e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x01ba88e5 objc_exception_throw + 44
    2   CoreFoundation                      0x01def376 -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 390
    3   CoreFoundation                      0x01e1cc29 +[NSDictionary dictionaryWithObjects:forKeys:count:] + 73
    4   Example                               0x00012233 -[CreatedCollectionViewController getCreatedNames] + 419
    5   Example                               0x0001202b -[CreatedCollectionViewController viewDidLoad] + 123
    6   UIKit                               0x0098733d -[UIViewController loadViewIfRequired] + 696
    7   UIKit                               0x009875d9 -[UIViewController view] + 35
    8   UIKit                               0x009bf11f -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 407
    9   UIKit                               0x009be943 -[UITabBarController transitionFromViewController:toViewController:] + 63
    10  UIKit                               0x009babed -[UITabBarController _setSelectedViewController:] + 281
    11  UIKit                               0x009baacc -[UITabBarController setSelectedViewController:] + 180
    12  UIKit                               0x009b7e30 __87-[UITabBarController _selectDefaultViewControllerIfNecessaryWithAppearanceTransitions:]_block_invoke + 43
    13  UIKit                               0x008ce81f +[UIView(Animation) performWithoutAnimation:] + 82
    14  UIKit                               0x009b7cd5 -[UITabBarController _selectDefaultViewControllerIfNecessaryWithAppearanceTransitions:] + 247
    15  UIKit                               0x009b8ae9 -[UITabBarController viewWillAppear:] + 148
    16  UIKit                               0x0098b04b -[UIViewController _setViewAppearState:isAnimating:] + 448
    17  UIKit                               0x0098b548 -[UIViewController __viewWillAppear:] + 114
    18  UIKit                               0x0099c105 -[UIViewController(UIContainerViewControllerProtectedMethods) beginAppearanceTransition:animated:] + 199
    19  UIKit                               0x009a1a5e -[UINavigationController _startCustomTransition:] + 1062
    20  UIKit                               0x009ae8f7 -[UINavigationController _startDeferredTransitionIfNeeded:] + 688
    21  UIKit                               0x009af4e9 -[UINavigationController __viewWillLayoutSubviews] + 57
    22  UIKit                               0x00af00d1 -[UILayoutContainerView layoutSubviews] + 213
    23  UIKit                               0x008d7964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
    24  libobjc.A.dylib                     0x01bba82b -[NSObject performSelector:withObject:] + 70
    25  QuartzCore                          0x0455045a -[CALayer layoutSublayers] + 148
    26  QuartzCore                          0x04544244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
    27  QuartzCore                          0x045440b0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
    28  QuartzCore                          0x044aa7fa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
    29  QuartzCore                          0x044abb85 _ZN2CA11Transaction6commitEv + 393
    30  QuartzCore                          0x045695b0 +[CATransaction flush] + 52
    31  UIKit                               0x008669bb _UIApplicationHandleEventQueue + 13095
    32  CoreFoundation                      0x01db277f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    33  CoreFoundation                      0x01db210b __CFRunLoopDoSources0 + 235
    34  CoreFoundation                      0x01dcf1ae __CFRunLoopRun + 910
    35  CoreFoundation                      0x01dce9d3 CFRunLoopRunSpecific + 467
    36  CoreFoundation                      0x01dce7eb CFRunLoopRunInMode + 123
    37  GraphicsServices                    0x03be85ee GSEventRunModal + 192
    38  GraphicsServices                    0x03be842b GSEventRun + 104
    39  UIKit                               0x00868f9b UIApplicationMain + 1225
    40  Stand                               0x00013a3d main + 141
    41  libdyld.dylib                       0x02575701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

The ultimate goal is to pass the userID from the profile.m file to the tab controller and allow each tab to have access to the userID, not sure what I am doing wrong, if someone can notice the error or let me know how I can have it so that it is not null and accessible?

Update I am thinking maybe it has to do with not being able to push a tabcontroller according to apple's guidelines, could that be the case? If so how do I go around it, or what options do I have?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Lion789
  • 4,402
  • 12
  • 58
  • 96

1 Answers1

1

Hi the problem here is that you are trying to push tab bar controller in navigation controller but apple forbids it Link .So you can add the tabbar controller modally or create a custom tab bar in a view controller and push it

souvickcse
  • 7,742
  • 5
  • 37
  • 64
  • Well adding the self gives me an error saying expected ( and retain is the same as strong ... http://stackoverflow.com/questions/7796476/property-definitions-with-arc-strong-or-retain – Lion789 May 17 '14 at 10:22
  • thn you can add a private property on the .m file. i don't have the mc now otherwise i ll be able to give the code – souvickcse May 17 '14 at 16:22
  • I included a property and tried to set it, but in the .m file the id is still showing up as null... – Lion789 May 17 '14 at 17:56
  • and don't use remove this line userProfileId = [(TotalTabController*)self.tabBarController userProfileId]; – souvickcse May 17 '14 at 18:04
  • Does it print the value now? – souvickcse May 17 '14 at 18:21
  • Nope, the same thing null... everything the same – Lion789 May 17 '14 at 18:25
  • have you tried adding break point on this line userTabView.userProfileName = profileName; and check userTabView.userProfileName is not null? – souvickcse May 17 '14 at 18:28
  • Yeah, it passes in the name and the id, it somehow gets lost on the tab controller – Lion789 May 17 '14 at 18:30
  • You are pushing tabbarcontroller in navgationcontroller but it is not a good practice here is the apple documnetion link:https://developer.apple.com/library/IOs/documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/CombiningViewControllers.html we always push navigation controller on tabbarcotroller, so that might be the problem in your case – souvickcse May 17 '14 at 18:41
  • Yeah I was thinking that could be it as you can see the update I posted above a while ago... so what are my options then? – Lion789 May 17 '14 at 18:43
  • You can show the tab bar Modally or you can create a custom tabbar in a view controller[preferable] and push it in your navigation controller – souvickcse May 17 '14 at 18:46
  • Ok so yeah the tab controller seems to have been the issue created a custom one and the id does get passed now. – Lion789 May 23 '14 at 19:52