应用程序试图在目标上推送一个nil视图控制器

时间:2011-09-19 12:47:31

标签: iphone view null

在我的Iphone应用中,我有这个pb:Application tried to push a nil view controller on target <UINavigationController:  我有一个包含tableview的视图控制器,我希望如果选择了一行,则显示另一个视图控制器。 这是我的代码:

在RecherchePartenaireViewController.m

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

        recherchePartenaireDistanceViewController = [[RecherchePartenaireDistanceViewController alloc]  init];

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

在RecherchePartenaireDistanceViewController.h中:

@class RecherchePartenaireViewController;

@interface RecherchePartenaireDistanceViewController : UIViewController {

    RecherchePartenaireViewController *recherchePartenaireViewController;
}

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

和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

问题出在哪里?我真的看不到它。请嘿嘿....

3 个答案:

答案 0 :(得分:1)

尝试使用它:

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

}

而不是

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

答案 1 :(得分:1)

我想我知道你在做什么,但我不明白你想要实现的目标!你有一个包含另一个视图控制器的ViewController?

即。 RecherchePartenaireDistanceViewController包含RecherchePartenaireViewController

我认为,因为它是IBOutlet,所以你使用xib文件填充它。

我唯一能想到的是在xib文件中创建RecherchePartenaireDistanceViewController时出现了问题。

如果你这样做,你在控制台中看到了什么:

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

在将其添加到导航控制器之前?

PS

这条线的目的是什么?

self.recherchePartenaireDistanceViewController=recherchePartenaireDistanceViewController.recherchePartenaireViewController;

答案 2 :(得分:0)

如果RecherchePartenaireDistanceViewController与xib接口比初始化时使用以下语句,

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

而不是将其推送到导航控制器。