0

我的视图中的条形按钮项目确实加载方法有问题。我有一个被添加到超级视图的子视图,当我单击 barbuttonitem 时,它会使应用程序崩溃并且我收到此错误

*** -[DetailViewController performSelector:withObject:withObject:]: message sent to deallocated instance 0x27677fa0


- (void)viewDidLoad
{
    [super viewDidLoad];
    navBar.tintColor = [UIColor blackColor];
    UIColor *topGreen = [UIColor colorWithRed:246/255.f green:241/255.f blue:206/255.f alpha:1];
    UIColor *bottomGreen = [UIColor colorWithRed:242/255.f green:237/255.f blue:204/255.f alpha:1];
    CAGradientLayer *gradient = [CAGradientLayer layer];
    gradient.frame = self.view.bounds;
    gradient.colors = [NSArray arrayWithObjects:(id)topGreen.CGColor, (id)bottomGreen.CGColor, nil];
    [self.view.layer insertSublayer:gradient atIndex:0];
    backButton = [[UIBarButtonItem alloc] initWithTitle:@"Map" style:UIBarButtonSystemItemAction target:self action:@selector(returnToMap:)];
    UINavigationItem *navButton = [[UINavigationItem alloc]init];
    navButton.leftBarButtonItem = backButton;
    [navBar pushNavigationItem:navButton animated:YES];
    navBar.topItem.title = title;
    NSLog(@"Reached");
    //[self returnToMap];
    //Do any additional setup after loading the view from its nib.
}

我不知道如何解决这个问题。我已经尝试将 barbutton 添加为属性并对其进行同步,但似乎没有任何效果。任何帮助都会很棒

4

1 回答 1

0

问题不在于UIBarButtonItem,而在于DetailViewController实例 - 您太早地发布它,或者没有保留参考。

于 2013-03-25T13:45:51.933 回答