2012-09-20 67 views
0

我創建了一個基於視圖的應用程序。我在視圖和兩個按鈕上放置了一個導航欄。我想在按下按鈕後更改導航欄的標題。在IB中,我已將按鈕與相應的操作相連接。調試顯示操作正在調用,但導航欄的標題未更改。更改UINavigationBar的標題

請幫忙!

// 
// NavBarViewController.h 

#import <UIKit/UIKit.h> 

@interface NavBarViewController : UIViewController { 

} 

-(IBAction) clickedOne: (id)sender; 
-(IBAction) clickedTwo: (id)sender; 

@end 
// 
// NavBarViewController.m 

#import "NavBarViewController.h" 

@implementation NavBarViewController 

-(IBAction) clickedOne: (id)sender { 
    self.navigationItem.title = @"1"; 
} 

-(IBAction) clickedTwo: (id)sender { 
    self.navigationItem.title = @"2"; 
} 


- (void)didReceiveMemoryWarning { 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc that aren't in use. 
} 

- (void)viewDidUnload { 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 


- (void)dealloc { 
    [super dealloc]; 
} 

@end 
+0

請使用標籤來說明這個問題涉及到哪些技術。如果您使用現有的標籤(例如Php,.net等 – NiladriBose

回答

1

我找到了。我已經使用了UINavgationItem並將IBOutlet與UINavigationItem連接起來。

// 
// NavBarViewController.h 

#import <UIKit/UIKit.h> 

@interface NavBarViewController : UIViewController { 
    UINavigationItem *navBar; 
} 

@property (nonatomic, retain) IBOutlet UINavigationItem *navBar; 

-(IBAction) clickedOne: (id)sender; 
-(IBAction) clickedTwo: (id)sender; 

@end 

// 
// NavBarViewController.m 

#import "NavBarViewController.h" 

@implementation NavBarViewController 

@synthesize navBar; 

-(IBAction) clickedOne: (id)sender { 
    navBar.title = @"1"; 
} 

-(IBAction) clickedTwo: (id)sender { 
    navBar.title = @"2"; 
} 


- (void)didReceiveMemoryWarning { 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc that aren't in use. 
} 

- (void)viewDidUnload { 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 


- (void)dealloc { 
    [super dealloc]; 
} 

@end