简体   繁体   English

从以编程方式创建的TableView推送的空白详细信息视图

[英]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.

相关问题 从详细信息视图向TableView添加一行 - Add a row to a TableView from a Detail view iOS 6将数据从TableView传递到详细信息视图 - iOS 6 pass data from TableView to Detail View 如何将值从TableView传递到Detail View Controller? - How to pass value from TableView to Detail View Controller? TableView在Swift中推送到详细信息视图 - TableView Pushing to Detail View in Swift IOS UITableView contentOffSet 不再隐藏 header 从推送的详细信息视图返回 - IOS UITableView contentOffSet no longer hides header on return from pushed detail view 以编程方式将uibutton添加到详细视图 - adding uibutton to a detail view programmatically 以编程方式创建详细视图内容? - Creating detail view content programmatically? 如何获取以编程方式在放置在iOS中的表格视图中的单元格和单元格索引路径中的滚动视图中创建的视图的位置 - How to get position of view created programmatically in scrollview placed in cell and cell indexpath in tableview in iOS 如何在splitview控制器的详细视图中从表视图显示所选行的数据? - How can i display the data of the selected row from the tableview in the detail view in a splitview controller? 如何设置以编程方式创建的TableView的子类? (没有情节提要) - How to set the subclass of a TableView that was created programmatically? (no storyboards)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM