按下视图控制器后,右NavBar按钮项目消失

时间:2011-12-07 23:37:46

标签: ios uinavigationcontroller uinavigationbar

因此我们为RootViewController提供了一个带有UITableView的Nav Controller。然后,当用户单击表格单元格时,我们将EKEventController推送到Nav堆栈并显示表格单元格表示的事件的详细信息。

我正在尝试在右侧添加一个按钮,但它没有显示出来。

当用户点击表格单元格时,我正在添加按钮。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{  

    // Upon selecting an event, create an EKEventViewController to display the event.
    self.detailViewController = [[[EKEventViewController alloc] initWithNibName:nil bundle:nil]autorelease];            
    detailViewController.event = [self.eventsList objectAtIndex:indexPath.row];

    detailViewController.allowsEditing = NO;  
    UIBarButtonItem *locationMapViewButtonItem = [[UIBarButtonItem alloc] 
                                                  initWithTitle:@"Map"
                                                          style:UIBarButtonItemStylePlain 
                                                         target:self 
                                                         action:@selector(showMap:)];  
    self.navigationItem.rightBarButtonItem = locationMapViewButtonItem;  
    [locationMapViewButtonItem release];  
    UITableView *eventTableView = [[self.detailViewController.view subviews]objectAtIndex:0];  
    [self.navigationController pushViewController:detailViewController animated:YES];  
}

然后,当EKEvent控制器显示时,右侧栏按钮消失。

1 个答案:

答案 0 :(得分:3)

您需要设置正在推送的视图控制器的导航项,因此您的行:

self.navigationItem.rightBarButtonItem = locationMapViewButtonItem;

应该成为:

detailViewController.navigationItem.rightBarButtonItem = locationMapViewButtonItem;