我有一个表格视图,当按下其中一个项目时会显示一个新视图。问题是新视图的navigationItem
属性未显示。相反,前一个视图(表格视图)导航项似乎显示(表格视图的导航栏动画未更改)。
这是推送新视图的印刷机处理程序:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"--- showing asset picker");
ELCAssetTablePicker *picker = [[ELCAssetTablePicker alloc] initWithNibName:@"ELCAssetTablePicker" bundle: nil];
picker.parent = self;
picker.assetGroup = [self.assetGroups objectAtIndex:indexPath.row];
//[picker.assetGroup setAssetsFilter:[ALAssetsFilter allPhotos]];
[self.navigationController pushViewController:picker animated:YES];
[picker release];
}
以下是推送视图的viewDidLoad
方法(ELCAssetTablePicker
),其中self.navigationItem
的标题和按钮已更新:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
[self.tableView setAllowsSelection:NO];
NSMutableArray *tempArray = [[NSMutableArray alloc] init];
self.elcAssets = tempArray;
[tempArray release];
UINavigationItem* navigationItem = self.navigationItem;
UIBarButtonItem *doneButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneAction:)] autorelease];
[navigationItem addBackBarButtonItemWithTitle:@"Back" forController:self];
[navigationItem addRightBarButtonItem:doneButtonItem];
[navigationItem setTitle:@"Loading..."];
[self performSelectorInBackground:@selector(preparePhotos) withObject:nil];
}
为什么在将新视图推送到UINavigationController
时,导航栏是否未更新?
答案 0 :(得分:0)
让navigationItem
全球化。据我所知,它的参考被杀了。为什么不使用简单的self.navigationItem
。
- (void)viewDidLoad
{
[super viewDidLoad];
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
[self.tableView setAllowsSelection:NO];
NSMutableArray *tempArray = [[NSMutableArray alloc] init];
self.elcAssets = tempArray;
[tempArray release];
UIBarButtonItem *doneButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneAction:)] autorelease];
[self.navigationItem addBackBarButtonItemWithTitle:@"Back" forController:self];
[self.navigationItem addRightBarButtonItem:doneButtonItem];
[self.navigationItem setTitle:@"Loading..."];
[self performSelectorInBackground:@selector(preparePhotos) withObject:nil];
}