【发布时间】:2015-06-16 13:06:31
【问题描述】:
大家好,我正在尝试添加一个自定义导航栏,该导航栏在不同的类中声明,并且有一个按钮可以进行推送操作。 我最初的问题是,当应用程序由于 uinavicgationconreoller 崩溃而推送视图时,我以某种方式修复了该问题,现在它也崩溃了。这是我的代码:
#import "HomeViewController.h"
@implementation HomeViewController
-(void)viewDidLoad
{
[super viewDidLoad];
TopBar *navBar = [TopBar new];
[navBar addTopBarToScreen:self.view];
}
-(void)productSheetsButtonFunction
{
MainViewController* productSheetsView = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
[self.navigationController pushViewController:productSheetsView animated:YES];
}
这是我的类,它持有我调用的方法
-(void)addTopBarToScreen:(UIView *)screen
{
//create the top bar
UIView *topBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 64.f)];
topBar.backgroundColor = [UIColor whiteColor];
[screen addSubview:topBar]
//add the productSheetsButton
UIButton *productSheetsButton = [[UIButton alloc] initWithFrame:CGRectMake(96.f, 14.f, 36.f, 36.f)];
productSheetsButton.backgroundColor = [UIColor clearColor];
[productSheetsButton setBackgroundImage:[UIImage imageNamed:@"ingredients.png"] forState:UIControlStateNormal];
[productSheetsButton setBackgroundImage:[UIImage imageNamed:@"ingredients_active.png"] forState:UIControlStateHighlighted];
[productSheetsButton addTarget:self action:@selector(productSheetsButtonFunction) forControlEvents:UIControlEventTouchUpInside];
[topBar addSubview:productSheetsButton];
}
我知道问题出在我将按钮的目标添加到 self 时
【问题讨论】:
标签: ios objective-c uiviewcontroller uibutton