2013-02-06 2 views
2

내 3 UIToolBar 항목에 대해 3 UIViewControllers을 만들었지 만 홈 페이지 또는 기본보기 컨트롤러로 돌아가는 각 컨트롤러에 버튼을 만들 수 없습니다. 객관적인 것을 처음 접했을 때 친절히 도와주세요. 여기 보기 컨트롤러에 뒤로 버튼 추가하기

내 코드는

....

"ViewController.h"

#import "ViewController.h" 
#import "ContactInfoViewController.h" 
#import "DateViewController.h" 
#import "MessageViewController.h" 
@interface ViewController() 
@end 
@implementation ViewController 
- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
UIToolbar *toolbar = [[UIToolbar alloc] init]; 
toolbar.frame = CGRectMake(0, 417, self.view.frame.size.width, 44); 
UIBarButtonItem *contact = [[UIBarButtonItem alloc] initWithTitle:@"Contact" style:UIBarButtonItemStyleDone target:self action:@selector(ContactButton)]; 
UIBarButtonItem *flexiableItem1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]; 
UIBarButtonItem *date = [[UIBarButtonItem alloc] initWithTitle:@"Date" style:UIBarButtonItemStyleDone target:self action:@selector(DateButton)]; 
UIBarButtonItem *flexiableItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]; 
UIBarButtonItem *message = [[UIBarButtonItem alloc] initWithTitle:@"Message" style:UIBarButtonItemStyleDone target:self action:@selector(MessageButton)]; 
NSMutableArray *items = [[NSMutableArray alloc] initWithObjects:contact,flexiableItem1,date,flexiableItem,message, nil]; 
[toolbar setItems:items animated:YES]; 
[items release]; 
[self.view addSubview:toolbar]; 
[toolbar release]; 
} 
-(void)ContactButton 
{ 
ContactInfoViewController *secondViewcont = [[ContactInfoViewController alloc] init]; 
UINavigationController *navigCont = [[UINavigationController alloc] initWithRootViewController:secondViewcont]; 
[self presentViewController:navigCont animated:YES completion:nil]; 
} 
-(void)DateButton 
{ 
DateViewController *secondViewcont = [[DateViewController alloc] init]; 
UINavigationController *navigCont = [[UINavigationController alloc] initWithRootViewController:secondViewcont]; 
[self presentViewController:navigCont animated:YES completion:nil]; 
} 
-(void)MessageButton 
{ 
MessageViewController *secondViewcont = [[MessageViewController alloc] init]; 
UINavigationController *navigCont = [[UINavigationController alloc] initWithRootViewController:secondViewcont]; 
[self presentViewController:navigCont animated:YES completion:nil]; 
} 
- (void)didReceiveMemoryWarning 
{ 
[super didReceiveMemoryWarning]; 
} 
@end 

답변

4

viewDidLoad에서

는이

같이 할 수있는 두 번째 뷰 컨트롤러에 사용자 정의 버튼 추가
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonPressed:)]autorelease]; 


- (IBAction)doneButtonPressed:(id)sender 
{ 
    [self dismissViewControllerAnimated:YES completion:nil]; 
} 
+0

감사합니다 ... 잘 작동합니다. :) – Newbee

관련 문제