i am creating a toolbar application, in that application all toolbar icons and actions done successfully.But when i used the icon for next view calling and from that view i am calling a back button then it will crashed..here i am adding my code
/////In View Did load
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];
///after that
-(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";
}
///in FirstViewController.m
-(IBAction)back:(id)sender
{
ViewController *objectViewController=[[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];
[self.view addSubview:objectViewController.view];
}
When i clicked the back button it will crashed..please give me the solution
just remove from superview of the current view for ex..