[英]Blank detail view pushed from a TableView that was created programmatically
我的设置使用的是故事板,在其中创建登录名,然后使用主屏幕,用户可以在其中按下按钮以显示其消息。
这些显示在以编程方式实例化的表中。
然后,我想从该表中按下一行以详细介绍该行,但是当我执行此操作时,显示的视图为空白,但是与该类关联的所有方法均被触发(视图已加载,依此类推)。
我确实尝试了10种不同方式,采用了其他人针对他们的问题提出的不同解决方案,但没有任何效果。
编写新视图并将其推送的代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
messageDetail *messageDetailView = [[messageDetail alloc]initWithNibName:nil bundle:nil];
messageDetailView.message = [entityObjects objectAtIndex:indexPath.row];
[self.navigationController pushViewController:messageDetailView animated:YES];
}
DetailView的ViewDidLoad:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
NSLog(@"Message Detail:\n%@",message);
messageTitle.text = message.message_title;
messageBody.text = message.message_xml;
}
我尝试使用segueIdentifier路由,然后截取prepareSegue:将数据添加到新视图中,但是由于tableView是通过编程方式创建的,因此没有segue。
我尝试通过以下方式从情节提要中实例化视图:
messageDetailView = [self.storyboard instantiateViewControllerWithIdentifier:@"MDV"];
但是该应用程序崩溃,因为即使我设置了标识符,也没有带有标识符的视图。
您将nil作为笔尖名称发送,如果您没有笔尖文件,则不要使用initWithNibName函数分配消息详细信息视图。
使用原始的init或initWithFrame。 无论哪种适合您。
祝好运
我基本上在这里用此代码做了同样的事情。 希望这可以帮助
Detail_View *next=[[Detail_View alloc] initWithNibName:@"Detail_View" bundle:nil];
//These are just values that I needed to set before going to the next page.
//You can use this if you want to pass over the value of your table row
//otherwise ignore this
next.htmlContents= [[storage_array objectAtIndex:indexPath.row]objectForKey:@"title"];
next.titleText=[[storage_array objectAtIndex:indexPath.row] objectForKey:@"title"];
[self.navigationController pushViewController:next animated:YES];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.