我正在開發一個具有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