Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

StevenHu

macrumors member
Original poster
Sep 3, 2009
80
0
Southern CA
I have created an app in which the main view's tableview lists the cells correctly, and correctly slides on the viewController with HTML pages for each cell that was tapped.

MainViewController shows each of the selections like this:

Code:
	ChampionsViewController *championsViewController = [[ChampionsViewController alloc]
			  initWithNibName:@"ChampionsViewController" bundle:nil];
	[self.menuList addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:
		@"Champions By Design", kTitleKey,
		championsViewController, kViewControllerKey,
		nil]];
	[championsViewController release];



The above view controller displays the HTML page with the following code. All the other view controllers use the same code; just the file names and titles are different:



Code:
-(void)viewDidLoad
{
	[super viewDidLoad];
	
	self.title = @"Champions";
	
	CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
	applicationFrame.origin.y = 0;
	UIWebView *webView = [[UIWebView alloc] initWithFrame:applicationFrame];
	webView.autoresizingMask = (UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight);
	
	NSString *basePath = [[NSBundle mainBundle] bundlePath];
	NSURL *baseURL = [NSURL fileURLWithPath:basePath];
	NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Champions" ofType:@"htm"];
	NSString *htmlString = [NSString stringWithContentsOfFile:filePath];
	if (htmlString) {
		[webView loadHTMLString:htmlString baseURL:baseURL];
	}
	
	[self.view addSubview:webView];
	[webView release];
}


The above works fine on my iPhone. Now I'd like to make one of the selections display a table view instead of an HTML page. I had the brilliant(?) idea of right-clicking on Add... then on New File... then creating a new table view controller files with xib file. Then I copied and pasted the main view controller's .h and .m files into the new page's files.

Of course I updated the files: I changed the filename in the new .h and .m files to the new view controller's name, and changed the code (as seen above) to reflect new pages to link to. I also added this new view controller's .h filename to the #import list of the main view controller. I made up the xib file in IB with a tableView, and made the connections as usual.

This build results in no errors, but after I Build and Run on my iPhone 3.1.2 and click on the cell in the main view for the new view controller, it generates an EXC_BAD_ACCESS error and freezes. All other cells work fine.

Double-checking the code, I can see all the alloc's are correctly released (see the code above for sample alloc and release), so I can't figure out where that error is coming from.

Is my approach to creating a new table view controller the wrong way to go?

Thanks,
Steve
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.