【发布时间】:2013-10-01 01:10:51
【问题描述】:
我正在开发一个具有 TableView 的应用程序。当我按下任何单元格时,应用程序会转到下一个 ViewController。在这个 viewController 中,我通过代码创建了一个 TabBarController,它有 3 个子 ViewControllers。因此,我想将 TableView 中的变量传递给 TabBar 的子项。我可以将变量传递给 TabBar,我已经用 NSlog 函数观察了它。对我来说真的很奇怪,在子 ViewControllers 中我还输入了一个 NSlog 并且变量为 null,但在输出中我首先看到了这个。
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
有人知道为什么我可以先查看 Children 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];
}
【问题讨论】:
-
对不起,我已经编辑了这个问题。你说的是真的
-
你是这个意思吗?
@implementation YPProjectViewController -(id) init { self = [super init]; if( !self ) return nil; NSLog(@"proId ID %@", _proId); return self; } -
但是,我不是在 init 中看的,我已经这样做给你看,我在 ViewDidLoad 中显示 proId 日志
标签: iphone ios objective-c uitableview uitabbarcontroller