我正在创建一个工具栏应用程序,在该应用程序中,所有工具栏图标和操作都已成功完成。但是当我使用该图标进行下一个视图调用并从该视图中调用一个后退按钮时,它会崩溃..这里我正在添加我的代码
/////在视图中加载
objectLabel = [[UILabel alloc]init];
objectLabel.frame = CGRectMake(10, 10, 300, 40);
objectLabel.text = @"Press Button";
[self.view addSubview:objectLabel];
NSLog(@"label");
objectToolbar=[UIToolbar new];
objectToolbar.barStyle = UIBarStyleBlackTranslucent;
[objectToolbar sizeToFit];
objectToolbar.frame = CGRectMake(0, 410, 320, 50);
NSLog(@"toolbar");
UIBarButtonItem *systemItem1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:@selector(pressButton1:)];
UIBarButtonItem *systemItem2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
target:self
action:@selector(pressButton2:)];
UIBarButtonItem *systemItem3 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera
target:self
action:@selector(pressButton3:)];
UIBarButtonItem *flexItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil];
NSArray *items = [NSArray arrayWithObjects: systemItem1, flexItem, systemItem2, flexItem, systemItem3, nil];
[objectToolbar setItems:items animated:NO];
[self.view addSubview:objectToolbar];
///之后
-(void) pressButton1:(id)sender{
// objectLabel.text = @"Add";
FirstViewController *objectFirstViewController=[[FirstViewController alloc]initWithNibName:@"FirstViewController" bundle:nil];
[self.view addSubview:objectFirstViewController.view];
}
-(void) pressButton2:(id)sender{
objectLabel.text = @"Take Action";
}
-(void) pressButton3:(id)sender{
objectLabel.text = @"Camera";
}
///在FirstViewController.m中
-(IBAction)back:(id)sender
{
ViewController *objectViewController=[[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];
[self.view addSubview:objectViewController.view];
}
当我单击后退按钮时,它会崩溃..请给我解决方案