[英]Blank detail view pushed from a TableView that was created programmatically
My setup is using a storyboard in which I create a login, then a home screen in which the user can press a button to display their messages. 我的设置使用的是故事板,在其中创建登录名,然后使用主屏幕,用户可以在其中按下按钮以显示其消息。
These are displayed in a table which is instantiated programmatically. 这些显示在以编程方式实例化的表中。
From this table I then want to press a row to go into detail about that row, but when i do this the view displayed is blank but all methods associated with the class are being fired (view did load, and so on). 然后,我想从该表中按下一行以详细介绍该行,但是当我执行此操作时,显示的视图为空白,但是与该类关联的所有方法均被触发(视图已加载,依此类推)。
I have literally tried 10 different ways from different solutions others had had suggested on their questions but nothing works. 我确实尝试了10种不同方式,采用了其他人针对他们的问题提出的不同解决方案,但没有任何效果。
Code to make new view and push it: 编写新视图并将其推送的代码:
- (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];
}
ViewDidLoad of DetailView: 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;
}
I have tried using a segueIdentifier route and then intercepting the prepareSegue: to add data to the new view, but as the tableView is created programmatically there is no segue. 我尝试使用segueIdentifier路由,然后截取prepareSegue:将数据添加到新视图中,但是由于tableView是通过编程方式创建的,因此没有segue。
I have tried instantiating the view from storyboard via: 我尝试通过以下方式从情节提要中实例化视图:
messageDetailView = [self.storyboard instantiateViewControllerWithIdentifier:@"MDV"];
But the app crashes as there is no view with identifier, even though i set the identifiers. 但是该应用程序崩溃,因为即使我设置了标识符,也没有带有标识符的视图。
You send nil as nib name, if you do not have a nib file do not allocate the message detail view with initWithNibName function. 您将nil作为笔尖名称发送,如果您没有笔尖文件,则不要使用initWithNibName函数分配消息详细信息视图。
Use raw init or initWithFrame. 使用原始的init或initWithFrame。 Whichever works for you. 无论哪种适合您。
Good luck 祝好运
I basically did the same thing with this code here. 我基本上在这里用此代码做了同样的事情。 Hope this helps 希望这可以帮助
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.