我创建了一个应用程序,它在表格视图中显示设备中的联系人,当我单击一行时,它将在另一个视图上显示该联系人的详细信息。这就是故事板的样子:
在我的didSelectRowAtIndexPath中,我有这段代码:
NewViewController *WVC = [self.storyboard instantiateViewControllerWithIdentifier:@"NewViewController"];
[self.navigationController pushViewController:WVC animated:YES];
当我运行应用程序时,该应用程序看起来像:
然而,当我点击一行时,会显示详细信息,但是这样:
有人可以让我知道我哪里出错了,先谢谢。
NewViewController.m中的代码
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor whiteColor];
nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 100, 300, 20)];
mylabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 125, 300 , 20)];
[nameLabel setText:@"Name :"];
[mylabel setText:_LabelText];
[self.view addSubview:nameLabel];
[self.view addSubview:mylabel];
myPhonelabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 175, 300, 20)];
[myPhonelabel setText:@"Contact Number :"];
PhoneLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 200, 300, 20)];
[PhoneLabel setText:_phoneNumber];
[self.view addSubview:myPhonelabel];
[self.view addSubview:PhoneLabel];
myEmailLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 240, 300, 20)];
[myEmailLabel setText:@"Email ID :"];
EmailLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 265, 300, 20)];
[EmailLabel setText:_emailId];
[self.view addSubview:myEmailLabel];
[self.view addSubview:EmailLabel];
myBdayLabel =[[UILabel alloc]initWithFrame:CGRectMake(10, 315, 300, 20)];
[myBdayLabel setText:@"Date Of Birth :"];
BdayLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 335, 300, 20)];
[BdayLabel setText:_birthDate];
[self.view addSubview:myBdayLabel];
[self.view addSubview:BdayLabel];
myButton = [[UIButton alloc]initWithFrame:CGRectMake(10, 30, 300, 30)];
[myButton setTitle:@"Contact Details" forState:UIControlStateNormal];
[myButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
myButton.backgroundColor = [UIColor colorWithRed:0xBD/255.0 green:0xBE/255.0 blue:0xC2/255.0 alpha:1];
myButton.layer.cornerRadius = 10;
myButton.clipsToBounds = YES;
[self.view addSubview:myButton];
}
编辑:(答案) 经过大量的头部撞击和拔毛后,问题通过更换
解决了NewViewController *WVC = [self.storyboard instantiateViewControllerWithIdentifier:@"NewViewController"];
与
NewViewController *WVC = [[NewViewController alloc] init];
老实说,我不知道为什么前一个不起作用。
答案 0 :(得分:0)
如果您不需要导航栏,请使用隐藏它
[self.navigationController setNavigationBarHidden:YES];