为什么选择单元格后视图笔尖无法打开?

问题描述

| 我创建了nib文件,并且正确完成了所有连接。当我运行该应用程序并选择一个单元格时,新的笔尖根本无法打开。请帮忙!
    - (void)tableView:(UITableView *)tableView 
 didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    //Get the selected country
NSString *selectedCountry = [[NSString alloc] initWithFormat:@\"you pressed for this.\"];

//Initialize the detail view controller and display it.
DetailViewController *dvController = [[DetailViewController alloc] 
                                      initWithNibName:@\"DetailView\" bundle:[NSBundle mainBundle]];

dvController.selectedCountry = selectedCountry;
[self.navigationController pushViewController:dvController animated:YES];
[dvController release];
dvController = nil;

}
    

解决方法

        您似乎没有正确设置
delegate
(基于没有记录
NSLog
语句的输出),否则将正确记录
null
或某些对象值。您需要重新检查您的IB连接,或者如果您已通过编程方式进行了此操作,则执行
tableView.delegate = self;
    ,        尝试这个:
DetailViewController *dvController = [[DetailViewController alloc] 
                                      initWithNibName:@\"DetailView\" bundle:[NSBundle mainBundle]];

dvController.selectedCountry = selectedCountry;
[self.navigationController pushViewController:dvController animated:YES];
dvController = nil;
    ,        希望您尝试从listviewcontroller加载detailvewcontroller。表格视图是listviewcontroller的成员。 该问题的可能原因。 如果您要将listviewcontroller.view作为子视图添加到任何其他viewcontollers视图,则 [self.navigationController pushViewController:dvController动画:是];不工作。 因此,您应该获取应用程序委托的实例,然后执行以下操作。
YourAppDelegate *appDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];

[appDelegate .navigationController pushViewController:dvController animated:YES];
检查一下。如果这不是您遇到问题的原因,请告知控制台输出Deepak询问您。     ,        不要同时释放
dvController
并将其设置为
nil
-只做一个。     

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...