我已经用完全相同的代码完成了很多次,但由于某种原因,它今天无法正常工作。
ExampleViewController1 *exampleView = [[ExampleViewController1 alloc] initWithNibName:@"ExampleViewController1" bundle:nil];
[exampleView setProjectName:[[self.projectListArray objectAtIndex:indexPath.row] objectForKey:@"name"]];
NSLog(@"%@", [[self.projectListArray objectAtIndex:indexPath.row] objectForKey:@"name"]);
XAppDelegate.stackController pushViewController:exampleView fromViewController:nil animated:YES]
我的NSLog
打印正确。
My ExampleViewController1.h
文件声明如下:
@property(nonatomic, strong) NSString *projectName;
然后我在ExampleViewController1.m
's中执行此代码
-(void)viewDidLoad {
NSLog(@"%@", self.projectName);
self.projectNameLabel.text = self.projectName;
[super viewDidLoad];
}
我NSLog
的结果很好奇。NSLog
来自我的似乎viewDidLoad
在我的另一个之前被调用:
2012-04-22 10:59:41.462 StackedViewKit[43799:f803] (null)
2012-04-22 10:59:41.463 StackedViewKit[43799:f803] NewTest
我已经确认那里的(null)
值来自NSLog(@"%@", self.projectName);
,但这应该是第二个NSLog
调用...我不知道为什么它首先通过。
有人要求此代码:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// random color
self.view.backgroundColor = [UIColor colorWithRed:((float)rand())/RAND_MAX green:((float)rand())/RAND_MAX blue:((float)rand())/RAND_MAX alpha:1.0];
}
return self;
}