在我的 RootViewController 中,我将图像设置为 rightBarButtonItem 就像这样,但是在我创建的第二个 ViewController 中,这个“后退”按钮不会显示。我在模拟器和我的 iPhone 上运行它,我可以点击应该显示按钮的区域并调用 goBack{} 方法。只是图像没有显示。有什么想法吗?
此外,就图像而言,我导出它们的方式与导出所有其他图像的方式完全相同。所有其他人都工作正常。图像似乎没有问题,因为我已经用后退按钮图像替换了其他几个图像,但它们都没有显示。我很确定我正在以正确的顺序创建这些图像。无论如何,任何帮助将不胜感激。
从我的 NewGameViewController.m 文件中:
- (void)viewDidLoad {
[super viewDidLoad];
CGFloat startingPoint = 0.0;
CGRect bounds = self.view.bounds;
bounds.origin.y = startingPoint;
bounds.size.height -= startingPoint;
self.ivarNewGameTableView = [[UITableView alloc] initWithFrame:bounds style:UITableViewStyleGrouped];
self.ivarNewGameTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
self.ivarNewGameTableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:self.ivarNewGameTableView];
UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.png"]];
self.ivarNewGameTableView.backgroundView = backgroundImageView;
UIImage *mainNavBar = [UIImage imageNamed:@"startNewGameNavBar.png"];
UIImageView *navBarView = [[UIImageView alloc] initWithImage:mainNavBar];
[navBarView setFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
[self.navigationController.navigationBar addSubview:navBarView];
UIButton *back = [UIButton buttonWithType:UIButtonTypeCustom];
// neither one of the following lines work. I know they're supposed to be identical, but
// seen Xcode be picky.
back.frame = CGRectMake(0.0, 0.0, 54.0, 36.0);
// [back setFrame:CGRectMake(0.0, 0.0, 54.0, 36.0)];
[back addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
[back setImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
[back setImage:[UIImage imageNamed:@"backTouched.png"] forState:UIControlStateHighlighted];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:back];
self.navigationItem.leftBarButtonItem = backButton;
}
-(void)goBack {
NSLog(@"goBack called.");
// [self.ivarNewGameTableView pushViewController:];
}