2010-08-29 35 views
0

嗨,我試圖在窗口中顯示uiview類對象,但事情是,它沒有顯示不知道什麼原因,我無法解決請幫助我,這裏是我的代碼在窗口中顯示uiview對象

@interface Myview : UIViewController { 


    UIView *move_view; 

    UIButton *btn; 



} 


@end 




#import "Myview.h" 


@implementation Myview 

// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. 
- (id)init { 
    if (self = [super init]) { 

     // Custom initialization 
     [move_view setFrame:CGRectMake(41, 91, 64, 82)]; 
     [move_view setBackgroundColor:[UIColor redColor]]; 


     btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
     [btn setFrame:CGRectMake(113, 298, 72, 37)]; 
     [btn setTitle:@"Move" forState:UIControlStateNormal]; 
     [btn addTarget:self action:@selector(moveaview) forControlEvents:UIControlEventTouchUpInside]; 

    } 
    return self; 
} 



// Implement loadView to create a view hierarchy programmatically, without using a nib. 
- (void)loadView { 

    [super loadView]; 
    [self.view addSubview:move_view]; 
    [self.view addSubview:btn]; 
} 

謝謝

回答

1

我想你要的Alloc +初始化init方法的視圖。此外,你確定你有正確的alloc + init的UIViewController並附加到AppDelegate窗口? 其他一些言論:

  • 不要叫MyView的一個UIViewController子類,代碼更難理解
  • 如果您正在加載從NIB/XIB控制器你最好ovverrid方法- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
+0

謝謝男人這個工作負載嚴重殺死我 謝謝你的幫助,我只是不能相信我跳過那部分感謝很多rano – Radix 2010-08-29 08:44:08

+0

@Radix,很高興它幫助。嘗試將Interface Builder用於這樣的小任務,它將正確地管理IBOutlets alloc和init – rano 2010-08-29 08:48:45