在标签控制器中传递UserId时出错?

时间:2014-05-17 09:01:09

标签: ios objective-c

我不知道为什么我一直收到这个错误,我确实通过按下按钮从配置文件视图控制器传递userId:

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];

NSLog打印出正确的用户ID,然后我将它添加到.h文件中的选项卡控制器中,如下所示:

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

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

在.m文件中如下:

@synthesize userProfileId, userProfileName;

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

但NSLog在.m文件中打印出null ......

然后我在其中一个标签视图.m文件中调用它:

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

然后得到这个错误:

错误是:

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) 

最终目标是将userID从profile.m文件传递到选项卡控制器,并允许每个选项卡访问用户ID,不确定我做错了什么,如果有人可以注意到错误或让我知道我怎么能拥有它,以便它不是空的和可访问的?

更新 我想也许这与根据苹果的指导方针无法按下tabcontroller有关,可能就是这种情况吗?如果是这样,我该如何解决它,或者我有什么选择?

1 个答案:

答案 0 :(得分:1)

这里的问题是你试图在导航控制器中推动标签栏控制器,但苹果禁止它Link。因此,您可以模态添加标签栏控制器或在视图控制器中创建自定义标签栏并推送它