2012-03-03 81 views
0

我的按鈕不會顯示。有誰知道爲什麼?將UIButton添加爲子視圖,但不顯示。

#import "ViewController.h" 


@implementation ViewController 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 


    CTrial *tt = [CTrial alloc]; 
    [tt hellothere:self]; 
} 


///////////////////////////// 
#import "CTrial.h" 
@implementation CTrial 


- (void) hellothere: (UIViewController*) ss 
{ 
    UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    [btn2 setTag:200]; 
    [btn2 addTarget:self action:@selector(menuSetup:) forControlEvents:UIControlEventTouchUpInside]; 
    [btn2 setFrame:CGRectMake(0,0,300,200)]; 
    [ss.view addSubview:btn2]; 
} 

我已經試過 「身份證」

- (id) hellothere: (UIViewController*) ss 

與回報,但仍然沒有

#import <UIKit/UIKit.h> 
#import "CButton.h" 

@interface CTrial : //UIView 

-(void) menuSetup:(UIButton*) btn; 
- (id) hellothere: (UIViewController*) ss; 
//- (void) hellothere: (UIViewController*) ss; 
@end 

回答

1

使用

UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 

您通常使用UIButtonTypeCustom,如果你想顯示一個自定義的對照例如,顯示圖像而不是古典按鈕,但由於您沒有爲按鈕分配任何圖像,所以它只是透明的,這就是爲什麼你看不到它。

除了使用

CTrial *tt = [[CTrial alloc] init]; 

alloc簡單地分配內存,不初始化對象

+0

它仍然只是一個黑色的背景屏幕...如果我刪除CTrial實例它是一個灰色的背景 – jdl 2012-03-03 22:26:08

+0

@jdl抱歉,我沒有注意到它。我編輯了我的答案。 – Saphrosit 2012-03-03 22:31:25

+0

你需要繼承什麼? ... UIView,它可以是什麼...否則你不能「分配」? – jdl 2012-03-03 22:32:56

相關問題