2011-08-02 5 views
0

나는 처음으로 죄 많은 아이폰 앱을 쓰고있다. 로그인 화면이 준비되었습니다. 내 메인 윈도우에서 로그인 자격 증명에 대한보기를 구현하고보기 (텍스트 상자 등)에 모든 UI를 추가합니다.iOS : 첫 번째 앱의 초보자 도움말 :보기를 전환 하시겠습니까?

이제 어떻게 되나요?

내 자격 증명을 확인하고 괜찮 으면 기본 창에서 login-view를 삭제하고 모든 정보가 포함 된 기본보기를 표시합니다.

하는 방법?

버튼 이벤트를 loginviewcontroller에 쉽게 추가하고, 거기에서 logindata를 확인하고 기본 창에 대한 액세스 권한을 얻고 문제 자체없이 뷰 자체에서 죽일 수 있습니까? 또는 메인 윈도우의보기에서 버튼 이벤트를 선언하고 모든 것을 수행해야합니까?

내 코드 : 당신의 ViewController에서

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil andDelegate:(id)delegate 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
     UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
     button.frame = CGRectMake(self.view.frame.size.width/2 - 55.0f, self.view.frame.size.height/2 + 85.0f 
           , 110.0f, 35.0f); 
     [button setTitle:@"title" forState:UIControlStateNormal]; 
     [button addTarget:delegate action:@selector(yourMethodInMainWindow:) forControlEvents: UIControlEventTouchDown]; 
     [self.view addSubview:button]; 
    } 
    return self; 
} 
+0

편집 된 코드를 @kovu 해보고 편집 주석을 읽어보고 잘못된 것을 확인하십시오. 또한 다음 번에 코드를 쉽게 포맷하십시오. 1588 rep-points 이후로 어떻게 사용하는지 알 것입니다. 대답을 받아 들여주세요. 작동하는 경우 +1하십시오. –

답변

1

: MainWindow를 가진 클래스

//maybe you will need to have more arguments added to you init method 
//for instance you might be using -(id)initWithNibName:bundle: right now 
//then just add delegate to it like -(id)initWithNibName:bundle:andDelegate: 
//just to clarify: delegate = reference to class you want to call a method in 
-(id)initMethod:(id)delegate { 
    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    self.button.frame = CGRectMake(self.view.frame.size.width/2 - 55.0f, self.view.frame.size.height/2 + 85.0f 
            , 110.0f, 35.0f); 
    [button setTitle:@"title" forState:UIControlStateNormal]; 
    [button addTarget:delegate action:@selector(yourMethodInMainWindow:) forControlEvents:UIControlEventTouchUpInside]; 
    [self.view addSubview:button]; 

} 

: 프로그래밍 방식으로 설정하는 한 가지 방법이다

-(void)yourMethodInMainWindow:(id)sender { 
    //do whatever you want to do. 
} 

. u가 nib를 사용한다면, 당신은 .h- 파일 och 타입 - (IBAction)buttonClicked:(id)sender에 메소드를 정의한 다음 인터페이스 빌더에 이들을 연결합니다.

새로운보기를 푸는 방법을 알고 계신 것 같군요. 예를 들어 presentModalViewController:animated:으로 처리 할 수 ​​있습니다. 이 모든 것은 이미 stackoverflow와 google에 있습니다.

대답이 here 인 경우 UIApplication 및 이에 따른 창에 액세스하는 방법에 대해 알아야 할 수도 있습니다.

+0

안녕하세요, 내가 이미 알고 있다고 말한 것들. 문제는 뷰에 앉아있는 Button-Method에서 MainWindow의 메서드를 호출하는 방법입니다. – Kovu

+0

mainWindow를'delegate'으로 뷰에 전달하고 다음과 같이 사용하는 것은 어떻습니까? 'button addTarget : delegate action : @selector (whatEverMethodInMainWindow :) forControlEvents : UIControlEventTouchUpInside]; ' –

+0

정확히 내가 무엇을 찾고 있었는지 생각하지만이 코드로 작업하는 방법을 이해하지 못합니다. 약간의 예를 만들 수 있습니까/당신이 대답하는 방법? – Kovu

0

이. 모든

우선, 그 네비게이션 컨트롤러,이어서 MainWindow.xib에

넣으 LoginViewController를 탐색 컨트롤러를 삽입한다. LoginviewController는 ur 로그인 ID와 암호 및 로그인 btn이 배치되는보기입니다.

이제 로그인 BTN 작업을 위해,이 방법을 쓰기 후에, 단지 인터페이스 빌더에 .xib 파일에 BTN에이 방법을 첨부

- (IBAction) loginBtnPressed : (id) sender{ 

    MainViewController *newObject = [MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil]; 

    [self.navigationController pushViewController:newObject animated:YES]; 

} 

을하는 방법을 쓰기.

관련 문제