ios dev help -noob

Associate
Joined
26 Nov 2006
Posts
1,091
if you know how to xcode can you please look at this code and explain why its not working? I've opened a webpage from selecting an item from the table but the detailview just doesnt load.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:[NSBundle mainBundle]]; [self.navigationController pushViewController:dvController animated:YES]; [dvController release]; dvController = nil; tableView.delegate=self; }

thanks
 
Firstly CODE TAGS! :P

Just from a quick look make sure your names are correct and I'm pretty sure your shouldn't be releasing the view controller just after you assign it. Just add a few break point's in and follow the view controller through creation (not all the background stuff, just these 5 lines) to see what is happening to it.
 
Right, I have a little bit more time to have a look at this for you now as I'm not stealth forum browsing at work.

Firstly, don't declare the child controller in the function, drag it out and dump it into your header file so your main controller can control it and do what it needs to do with it once that is released.

.h
Code:
#import "DetailViewController.h"

@interface MainController : UIViewController <UITableViewDelegate>
{
    DetailViewController *dvController;
}
@end

Now in the row select function only use detail controller, don't memory manage it, leave that for the main controller and put the memory management into the viewDidUnload and dealloc functions.

.m
Code:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
	if (dvController == nil)
	{
		dvController = [[MatchDetails alloc] initWithNibName:@"DetailViewController" bundle:nil];
	}

	[self.navigationController pushViewController:dvController animated:YES];
}

- (void)viewDidUnload
{
	self.dvController = nil;
}


- (void)dealloc
{
	[dvController release];

	[super dealloc];
}

This code was ripped out of one of my apps that's in the app store, so I know it works fine. If it's still not working after trying this example then try re-checking your naming of various variables and .xib files.
 
Last edited:
Back
Top Bottom