0

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.

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:

- (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.

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Sean Lintern
  • 3,103
  • 22
  • 28

2 Answers2

0

You send nil as nib name, if you do not have a nib file do not allocate the message detail view with initWithNibName function.

Use raw init or initWithFrame. Whichever works for you.

Good luck

Can Leloğlu
  • 271
  • 1
  • 4
  • 11
  • I misunderstood the question, you should definitely use initwithnibname with a valid nib file name. Is this messagedetail class is a view or view controller? – Can Leloğlu Jan 04 '13 at 16:24
  • messageDetail is a UIViewController on the MainStoryboar.Storyboard – Sean Lintern Jan 07 '13 at 09:56
  • Then set the root to the current view and push the message detail after. I assume you are pushing the new view controller on another view. – Can Leloğlu Jan 07 '13 at 18:44
0

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];
BigT
  • 1,413
  • 5
  • 24
  • 52
  • I am using storyboards and cannot therefore set a nib name ? – Sean Lintern Jan 03 '13 at 15:45
  • Check out this question http://stackoverflow.com/questions/8724779/how-to-open-view-controller-from-didselectrowatindexpath-within-storyboard – BigT Jan 03 '13 at 15:55
  • in this example above that you supplied, are you using storyboard or Xib's ? – Sean Lintern Jan 07 '13 at 09:57
  • No this wasn't using storyboards. Just use the first line as an example to yours. You are not setting a nib name. yours is set to nill. I want my view to go to the detail view so I have initWithNibName:@"Detail_View". You should do the same. Even with storyboards – BigT Jan 07 '13 at 16:14
  • Still blank im afraid, Ive tried using nil and setting a storyboard identifier. – Sean Lintern Jan 08 '13 at 13:07