tags:

views:

914

answers:

2

App Description: I have a UIWebview and a Toolbar beneath it. A button on the toolbar should bring up a modal table view, but it does not.

The toolbar has four buttons:

Previous: Goes to previous site

Next: Goes to the next site (these two being different than the default goForward and goBack methods)

Menu: Display a modalViewController with a TableView of all the available sites (sites will be limited to an array of site links that the next and previous buttons cycle through)

Refresh: Refreshes current site

Application has four main classes/files

WebAppDelegate.h and .m

ListViewController.h and .m (which has the Table View in its xib and the code to fill the table in the .m/ be the modal view controller)

There is only one warning and no errors.

Warning: 'WebAppDelegate' may not repsond to '-presentModalViewController:animated:'

When I run the program, everything is fine until I click the Menu button. I receive this runtime error

[WebAppDelegate presentModalViewController:animated:]: unrecognized selector sent to instance

Below is the code for the Menu button, which is currently in WebAppDelegate.m

-(IBAction)menu:(id)sender {
ListViewController *aListView=[[ListViewController alloc] initWithNibName:@"ListViewController" bundle:[NSBundle mainBundle]];
[self setListController:aListView];
aListView.modalTransitionStyle=UIModalTransitionStyleCoverVertical;
[self presentModalViewController:aListView animated:YES];
[aListView release];
}

Any ideas on what causes the application to crash and why the modal table view does not display?

+3  A: 

The error message tells you exactly what your problem is - you're sending a selector to an object that doesn't respond to that selector.

[self presentModalViewController:aListView animated:YES];

self in this case in your instance of WebAppDelegate, which is probably a subclass of NSObject, not UIViewController. presentModalViewController:animated: is a method on UIViewController, so you need to send that message to whatever view controller is currently displayed (or perhaps a navigation controller) if you want to present another view controller modally.

Do not ignore compiler warnings - the one warning you have is likely telling you that...

'WebAppDelegate' may not respond to '-presentModalViewController:animated:'

...which, again, is exactly your problem.

Sbrocket
+2  A: 
[self.navigationController presentModalViewController:aListView animated:YES];
Morion
Not sure where he insinuates that he has a navigation controller. If anything, I would be willing to bet that he doesn't have one, and it doesn't help to give an answer that could be confusing because it isn't explained fully.
Sbrocket
This worked, and now have a new runtime error (no other compile-time errors or warnings): "Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "ListViewController" nib but didn't get a UITableView.'"Something is wrong in the Table View code, but it's at least progressing.
LoganFrederick
SBrocket is right in that I do not have a navigation controller. I used self.listController, which might still be the wrong approach.
LoganFrederick