views:

267

answers:

1

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

Problem: The button runs through the code (tested with breakpoints and replacing the code) but doesn't display the alternate View.

My Hunch: It's probably a relationship problem in Interface Builder, as I receive no errors, warnings, or even runtime errors.

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

Code for the Menu button:

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

Code for the ListViewController (the ModalView):

#import "ListViewController.h"

static NSString *kCellIdentifier = @"MyIdentifier";
static NSString *kTitleKey = @"title";
static NSString *kViewControllerKey = @"listController";

@implementation ListViewController

@synthesize menuList;
@synthesize listController;
@synthesize modalViewController;

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];

 //Initialize the array.
 menuList = [[NSMutableArray alloc] init];

 //Add items
 [menuList addObject:@"Item 1"];
 [menuList addObject:@"Item 2"];

 //Set the title
 self.navigationItem.title = @"Test Items";
}

#pragma mark -
#pragma mark UIViewController delegate

- (void)viewWillAppear:(BOOL)animated
{
 // this UIViewController is about to re-appear, make sure we remove the current selection in our table view
 NSIndexPath *tableSelection = [self.tableView indexPathForSelectedRow];
 [self.tableView deselectRowAtIndexPath:tableSelection animated:YES];
}


#pragma mark -
#pragma mark UITableViewDelegate

// the table's selection has changed, switch to that item's UIViewController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
 UIViewController *targetViewController = [[menuList objectAtIndex: indexPath.row] objectForKey:kViewControllerKey];
 [[self navigationController] pushViewController:targetViewController animated:YES];
}


#pragma mark -
#pragma mark UITableViewDataSource

// tell our table how many rows it will have, in our case the size of our menuList
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
 return [menuList count];
}

// tell our table what kind of cell to use and its title for the given row
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier];
 if (cell == nil)
 {
  cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellIdentifier] autorelease];
  cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
 }

 cell.textLabel.text = [[menuList objectAtIndex:indexPath.row] objectForKey:kTitleKey];

 return cell;
}

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}


- (void)didReceiveMemoryWarning {
 // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

 // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
 [super viewDidUnload];
 //menuList=nil;
}


- (void)dealloc {
    [super dealloc];
}

@end

I've Uploaded the Entire Project Project Downloadable: http://gamesource.biz/media/WebUploadable.zip

A: 

Please check about the duplicates before posting.

I have put an answer here

http://stackoverflow.com/questions/1814126/using-presentmodalviewcontroller-to-load-a-view/1818086#1818086

Madhup