2010-04-16 4 views

답변

1

alloc 임시보기 컨트롤러이며 initWithNibName:을 호출하십시오. 그런 다음 [self presentModalViewController:(the view controller you just made) animated:YES]; (또는 NO)으로 전화하십시오. 데이터를 전달하려면 다른보기 컨트롤러에서 메서드를 만들고이를 .h 파일에 추가 한 다음 첫 번째보기 컨트롤러의 .m 파일에 추가하고 가져 와서 클래스로 만들고 [theviewcontrollermadeearlier yourmethod:argument :argument etc.]; (예 :

)으로 호출합니다.

MyFirstViewController.h :

#import <UIKit/UIKit.h> 
#import "MySecondViewController.h" 
... 
@class MySecondViewController 
... 

MyFirstViewController.m :

... 
MySecondViewController *tempVC = [[MySecondViewController alloc] initWithNibName:@"MySecondView"]; 
[self presentModalViewController:tempVC animated:YES]; 
[tempVC passDataWithString:@"a string" andColor:yellowcolor]; 

MySecondViewController.h :

@interface MySecondViewController : UIViewController { 
... 
} 
- (void)passDataWithString:(NSString *)passedString andColor:(UIColor *)passedColor; 

MySecondViewController.m :

... 
- (void)passDataWithString:(NSString *)passedString andColor:(UIColor *)passedColor { 
// Do something 
} 

편집 : 이, 당신의 첫 번째보기 컨트롤러의 헤더 파일에서 @interface 섹션에서 IBOutlet IBAction *buttonPressed; 추가 버튼 트리거를 확인한 다음 }@end 사이에 추가하려면 - (IBAction)buttonPressed;
이동 Interface Builder에 넣고 IBAction을 버튼에 연결하십시오.
첫 번째보기 컨트롤러의 주 파일에 다음을 추가하십시오.

- (IBAction)buttonPressed { 
    // The code to execute when pressed 
} 
관련 문제