2011-12-23 59 views
1

我正在開發iOS 5應用程序。我想使用它的默認視圖以編程方式調整UIView大小。這是視圖命名爲cardView。UILabel和UIView返回viewDidAppear上的大小(0,0)

@interface ThreeCardsViewController : UIViewController 
{ 
    ... 
    IBOutlet UIView* cardView; 
    ... 
} 

@property (nonatomic, retain) IBOutlet UIView* cardView; 

... 

當我向viewDidAppear中的方法發送消息時,我得到的cardView大小爲0x0。

@implementation ThreeCardsViewController 

... 
@synthesize cardView; 
... 

- (void)viewDidAppear:(BOOL)animated 
{ 
    [super viewDidAppear:animated]; 
    [self setUpViews]; 
} 

- (void) setUpViews 
{ 
    ... 

    futureCardState.cardViewY = 
        [self computeDescriptionViewPosWith:futureCardState.cardViewSize]; 
    ... 

    [self showCard:pastCardState]; 
} 

- (CGFloat) computeDescriptionViewPosWith:(CGSize)newDescriptionViewSize 
{ 
    CGFloat newY; 

    newY = cardView.frame.size.height - newDescriptionViewSize.height; 

    return newY; 
} 

所有視圖,或uilabels具有大小(0,0)。

我敢肯定,這個看法與廈門國際銀行連接,使用Interface Builder

你知道爲什麼我得到(0,0)?我在哪裏可以做這個初始化?

+0

向我們展示'setUpView'的代碼。另外,確保你總是調用'super'的'viewDidAppear:'。 – mattjgalloway 2011-12-23 10:07:12

+1

你合成cardView嗎? – Maulik 2011-12-23 10:10:51

+0

我用新的細節更新了我的問題。 @mattjgalloway,我已經添加了[super viewDidAppear:...],但它還沒有工作。 – VansFannel 2011-12-23 10:24:27

回答

0

我已經找到了答案。

如果我使用self.cardView,它的工作原理!

- (CGFloat) computeDescriptionViewPosWith:(CGSize)newDescriptionViewSize 
{ 
    CGFloat newY; 

    newY = self.cardView.frame.size.height - newDescriptionViewSize.height; 

    return newY; 
} 
1

檢查Xib中的IBOutlets,並且不要忘記所有屬性的@synthesize。

+0

Xib中的所有IBOutlets都是正確的,並且所有屬性都有它的@synthesize。 – VansFannel 2011-12-23 10:23:15

0

0x0不是大小,它是分配對象的內存地址。並在調用方法之前在ViewDidAppear中執行。

cardView = [[UIView alloc]init]; 

這樣便解決了問題

+0

如果cardView尚未分配,我將收到一個異常。而且,對不起,這是我的錯。我使用了不正確的尺寸格式。 – VansFannel 2011-12-23 10:32:24

相關問題