Sezgin
Sezgin

Reputation: 249

Change UInavigationbar title back page

i have two screen. i want click button first screen after navigation bar change in second screen. i using storyboards

first screen code

-(IBAction) ChangeSecondPageTitle: (id) sender {

SecondViewController *second=[[self storyboard] instantiateViewControllerWithIdentifier:@"second"];
        second.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
          second.detailTitle.topItem.title=@"example";
        [self presentModalViewController:second animated:YES];
}

second screen.h

@property (weak, nonatomic) IBOutlet UINavigationBar *detailTitle;

Upvotes: 0

Views: 92

Answers (3)

Divyu
Divyu

Reputation: 1313

Actually the reason your code is not working is you set the property to your nav bar and then your viewDidLoad get called. In viewDidLoad it loads the nib file and return new allocated navBar. So to Solve this take a global string set it from first view and then in second in viewDidLoad set your navbar's title. Follow Adithya's answer for that.

Upvotes: 2

K..
K..

Reputation: 77

In second screen declare a property

@property (strong, nonatomic) NSString *newTitle;

and in viewDidLoad

     self.title  = _newTitle;

and in your first screen

  ...
  second.newTitle = @"NEW_TITLE";

Upvotes: 1

Adithya
Adithya

Reputation: 4705

I guessing you are trying to set title for your second screen navigation bar.

Use a navigation controller to present your second screen.

In SecondDetailViewController instance, maintain a NSString property.

@property (strong, nonatomic) NSString *navBarTitle;

In viewDidLoad, just set the title.

[self setTitle:navBarTitle];

Upvotes: 3

Related Questions