开发者

Application tried to push a nil view controller on target <UINavigationController

开发者 https://www.devze.com 2023-04-05 16:35 出处:网络
In my Iphone app I have this pb :Application tried to push a nil view controller on target <UINavigationController:

In my Iphone app I have this pb :Application tried to push a nil view controller on target <UINavigationController: I have a view controller that contains a tableview and I want that if one row is selected an other view controller to be displayed. Here is my code :

in RecherchePartenaireViewController.m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row==3){
        NSLog(@"RecherchePartenaireDistanceViewController...");

        recherchePartenaireDistanceViewController = [[RecherchePartenaireDistanceViewController开发者_StackOverflow社区 alloc]  init];

      self.recherchePartenaireDistanceViewController=recherchePartenaireDistanceViewController.recherchePartenaireViewController;
        [self.navigationController pushViewController:recherchePartenaireDistanceViewController animated:YES];
        [recherchePartenaireDistanceViewController release];
    }
}

In RecherchePartenaireDistanceViewController.h :

@class RecherchePartenaireViewController;

@interface RecherchePartenaireDistanceViewController : UIViewController {

    RecherchePartenaireViewController *recherchePartenaireViewController;
}

@property (nonatomic, retain) IBOutlet RecherchePartenaireViewController *recherchePartenaireViewController;
@end

and in RecherchePartenaireDistanceViewController.m

#import "RecherchePartenaireDistanceViewController.h"
#import "RecherchePartenaireViewController.h"

@implementation RecherchePartenaireDistanceViewController


@synthesize recherchePartenaireViewController;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

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

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

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

Where is the problem? I really can't see it. Please heeelp....


Try to use this:

- (void)dealloc
{
    [recherchePartenaireViewController release];
    [super dealloc];

}

instead of

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


I think I see what you're doing but I don't understand what you're trying to achieve! You have a ViewController that contains another view controller?

i.e. RecherchePartenaireDistanceViewController contains a RecherchePartenaireViewController

I assume that as it's an IBOutlet you're populating it using a xib file.

The only thing I can think of is that something is going wrong with the creation of your RecherchePartenaireDistanceViewController in the xib file.

What do you see in the console if you do this :

NSLog(@"controller : %@", recherchePartenaireDistanceViewController);

just before adding it to the navigation controller?

PS

What's the purpose of this line?

self.recherchePartenaireDistanceViewController=recherchePartenaireDistanceViewController.recherchePartenaireViewController;


if RecherchePartenaireDistanceViewController is with xib interface than use following statement while initializing,

recherchePartenaireDistanceViewController = [[RecherchePartenaireDistanceViewController alloc]  initWithNibName:@"RecherchePartenaireDistanceViewController" bundle:nil];

than push it to navigation controller.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号