2013-01-18 53 views
0

我在Xcode中用單個UITableViewController創建了一個新的單視圖項目(使用storyboard)。下面是設置代碼:自定義表格部分頁腳視圖 - 標籤不可見

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    _footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 44, 44)]; 
    _footerView.autoresizingMask = UIViewAutoresizingFlexibleWidth; 

    UILabel *l = [[UILabel alloc] initWithFrame:CGRectMake(60, 0, 44, 44)]; 
    l.text = @"Label Label Label Label Label Label Label Label Label"; 
    l.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth; 
    l.backgroundColor = [UIColor clearColor]; 

    [_footerView addSubview:l]; 

    _footerView.backgroundColor = [UIColor lightGrayColor]; 
} 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return 1; 
} 

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { 
    return _footerView.frame.size.height; 
} 

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { 
    return _footerView; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    return [tableView dequeueReusableCellWithIdentifier:@"Cell"]; 
} 

我要在定製表頁腳視圖標籤,在x = 60來繪製,但是當我運行該項目,在第一個標籤是無形的(縱向,屏幕附)。然後,如果我旋轉一次,它將變得可見,如果我旋轉回肖像它是可見的。

我錯過了什麼?

Label not visible Landscape

回答

0

你似乎初始化與44px的寬度和高度的頁腳視圖,但添加標籤的範圍之外。

嘗試,而不是執行以下操作:

_footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.tableView.frame), 44)]; 

_footerView.autoresizingMask = UIViewAutoresizingFlexibleWidth; 

UILabel *l = [[UILabel alloc] initWithFrame:CGRectInset(_footerView.bounds, 60.0f, 0.0f)]; 
l.text = @"Label Label Label Label Label Label Label Label Label"; 
l.autoresizingMask = UIViewAutoresizingFlexibleWidth; 
l.backgroundColor = [UIColor clearColor]; 

[_footerView addSubview:l]; 

_footerView.backgroundColor = [UIColor lightGrayColor]; 

作爲進一步的一點,儘量不要使用[UIColor clearColor]作爲標籤的背景顏色,如果你能幫助它 - 它顯著降低滾動性能。在這種情況下,您應該使用[UIColor lightGrayColor],以便它與其超級視圖相匹配。

+0

謝謝,這工作。 –