2012-02-14 6 views
0

Xcode 4.2에서 스토리 보드없이 여러 뷰를 구현하는 데 필요한 튜토리얼을 찾는 데 많은 어려움을 겪고 있습니다. 이는 클래스 용이므로 아직 스토리 보드를 사용할 수 없습니다. 난 단지 UIPicker와 함께 두 번째보기를하려고 할 때 버튼이 기본보기에서 클릭하면, 난 그냥 Xcode 의이 버전에 대한 하나를 찾을 수 없으며 이전 버전에서 충분히 혼란 스러울 정도로 다릅니다.Xcode의 다중 뷰 4.2

누군가가 나에게 내가 : 나는 당신이 좋은 핸들을에 얻을 수있는 UIView Programming Guide을 읽어야 생각

+0

나는 잘 모르겠다. Xcode의 버전은 귀하의 질문과 정확히 어떤 관계가 있습니까? 파일> 새로 만들기> 새 파일을 선택하여 UIView 하위 클래스를 만들 수 있습니다. – MGA

+0

그 작업을 수행 할 수 있었지만 처음보기의 단추에 어떻게 연결합니까? – user1208173

+0

어이 거기에 user1208173. 내 대답이 도움이 되었기를 바랍니다. 다른 질문이 있으면 알려주세요. 내 대답이 귀하의 문제를 해결하는 데 도움이된다면, 정답으로 선택하면 감사하겠습니다. 감사합니다! – MGA

답변

4

감사하겠습니다 내가이해야 할 일의 빠른 설명이나 새로운 튜토리얼을 줄 수 있다면 감사 어떤 도움 어떻게 UIView가 정확하게 작동하는지. nibs/storyboard가 새로운 iOS 개발자를 혼란스럽게하는 데 정말 좋습니다. 본질적

하는 UIViewController 사용하면 [self setView:someUIView]을 사용하여 viewDidLoad 또는 loadView있어서 설정 한 볼 수있다. 당신은 UIView을 viewcontroller의 "Main"뷰의 하위 뷰로 추가하여 더 많은 내용을 화면에 추가합니다. 예를 들어

-(void)loadView { 
    // Create a view for you view controller 
    UIView *mainView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    [self setView:mainView]; 

    // Now we have a view taking up the whole screen and we can add stuff to it 
    // Let's try a button, a UIButton is a subview of UIView 
    UIButton *newButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    // We need to set a frame for any view we add so that we specify where it should 
    // be located and how big it should be! 
    [newButton setFrame:CGRectMake(x,y,width,height)]; 
    // Now let's add it to our view controller's view 
    [self.view addSubview:newButton]; 

    // You can do the same with any UIView subclasses you make! 
    MyView *myView = [[MyView alloc] init]; 
    [myView setFrame:CGRectMake(x,y,width,height)]; 
    [self.view addSubview:myView]; 

} 

지금 여기에 우리는 우리의 ViewController who'se보기 그냥 다시 2 파단이있는 일반의 UIView입니다있다; newButton 및 myView MyView 클래스를 만들었으므로 서브 뷰도 포함되어있을 수 있습니다. 그래서이 예에서 우리가 지금이 버튼을 포함 볼 who'se보기 컨트롤러 것

// Here is the init method for our UIView subclass 
- (id)initWithFrame:(CGRect)frame 
{ 
    self = [super initWithFrame:frame]; 
    if (self) { 
     // Let's add a button to our view 
     UIButton *newButton2 = [[UIButton buttonWithType:UIButtonTypeRoundedRect]; 
     // Of course, the frame is in reference to this view 
     [newButton2 setFrame:CGRectMake(x,y,width,height)]; 
     // We add just using self NOT self.view because here, we are the view! 
     [self addSubview:newButton2]; 

    } 
    return self; 
}  

:의는 UIView 하위 모습 수 있는지 살펴 보자! 그러나보기 구조는 나무입니다.

  mainView 
     / \ 
    newButton  myView 
        \ 
       newButton2 

다른 질문이 있으면 알려주세요.

매트

+0

+1 시간을내어 주셔서, 당신의 도움이 PG를 읽지 않는 user1208173이되지 않기를 바랍니다 :) –