我正在开发一个具有TableView的应用程序。当我按任何单元格时,应用程序会转到下一个ViewController。在这个viewController我创建了一个TabBarController的代码有3个子ViewControllers。所以,我想将一个变量从TableView传递给TabBar的子项。我可以将变量传递给TabBar,我已经用NSlog函数来观察它。对我来说,真的很奇怪,在子ViewControllers中,我也输入了一个NSlog并且该变量为null,但是在输出中我首先看到了这一点。在ViewController和TabBar子项之间传递数据
2013-10-01 03:01:40.687 Prototype[38131:c07] proId (null) // This is the children log from vc2 ViewController "YPProjectViewController"
2013-10-01 03:01:40.697 Prototype[38131:c07] projectID 433 // This is the TabBar LOG YPTabBarViewController
有人知道为什么我可以首先孩子NSLog?也许有解决方案。
#import "YPTabBarViewController.h"
#import "YPProjectViewController.h"
#import "YPCommentsViewController.h"
#import "YPProposalsViewController.h"
@interface YPTabBarViewController()
@property (nonatomic,strong)UITabBarController *tabBar;
@end
@implementation YPTabBarViewController
@synthesize tabBar;
@synthesize projectId = _projectId;
- (void)viewDidLoad
{
[super viewDidLoad];
[self setUpTabBar];
}
// Set up tabBar
-(void)setUpTabBar
{
YPCommentsViewController *vc1 = [[YPCommentsViewController alloc] init];
vc1.title = @"Comments";
vc1.view.backgroundColor = [UIColor clearColor];
UINavigationController *contentNavigationController = [[UINavigationController alloc] initWithRootViewController:vc1];
YPProjectViewController *vc2 = [[YPProjectViewController alloc] init];
vc2.title = @"Project";
vc2.view.backgroundColor = [UIColor clearColor];
vc2.proId = _projectId;
NSLog(@"PROJECT ID %@", vc2.proId);
// UINavigationController *contentNavigationController2 = [[UINavigationController alloc] initWithRootViewController:vc2];
YPProposalsViewController *vc3 = [[YPProposalsViewController alloc] init];
vc3.title = @"Proposal";
vc3.view.backgroundColor = [UIColor clearColor];
UINavigationController *contentNavigationController3 = [[UINavigationController alloc] initWithRootViewController:vc3];
tabBar = [[UITabBarController alloc] init];
tabBar.viewControllers = @[contentNavigationController,vc2,contentNavigationController3];
tabBar.selectedIndex = 1;
[tabBar.view setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
[tabBar willMoveToParentViewController:self];
[self addChildViewController:tabBar];
[tabBar didMoveToParentViewController:self];
[self.view addSubview:tabBar.view];
}
对不起,我编辑了这个问题。这是真的你说什么 – croigsalvador
你的意思是? '@implementation YPProjectViewController - (id)init { self = [super init]; if(!self)return nil; NSLog(@“proId ID%@”,_proId); 回归自我; }' – croigsalvador
但是,我没有看到它在初始化,我已经做到了这一点来显示你,我显示proId登录ViewDidLoad – croigsalvador