2014-03-28 39 views
0

我只想在TableView。在TableView的最後一節,以顯示頁腳文本我有很多TableView部分的它來自API.But我只需要在部分的tableView如何做到這一點的底部顯示頁腳信息?如何僅在tableview的文本最後一部分添加頁腳文本?

(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { 
UIView *footer = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 540, 10)]; 
footer.backgroundColor = [UIColor clearColor]; 

UILabel *lbl = [[UILabel alloc]initWithFrame:footer.frame]; 
lbl.backgroundColor = [UIColor clearColor]; 
lbl.text = @"Your Text"; 
lbl.textAlignment = NSTextAlignmentCenter; 
[footer addSubview:lbl]; 

return footer; 
} 


- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { 
return 10.0; 
} 

目前即時通訊使用此代碼。此節目中的所有部分bottom.I只需要在最後的tableview部分的底部顯示。

+0

有關添加頁腳'Tableview'本身是什麼。 – Akhilrajtr

+0

我需要在最後一節顯示一些文本 –

+0

我正在使用Section tableview可以告訴我如何在tableView本身實現? –

回答

3

試試這個

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { 
UIView *footer = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 540, 55)]; 
if (section == array.count -1){ 
    footer.backgroundColor=[UIColor clearColor]; 
    lbl = [[UILabel alloc]initWithFrame:CGRectMake(0,0,540,40)]; 
    lbl.backgroundColor = [UIColor clearColor]; 
    lbl.text = @" Please add your message"; 
    lbl.textAlignment = NSTextAlignmentCenter; 
    [lbl setNumberOfLines:10];//set line if you need 
    [lbl setFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:14.0]];//font size and style 
    [lbl setTextColor:[UIColor blackColor]]; 
    [footer addSubview:lbl]; 
    self.jobsTableView.tableFooterView=footer; 

} 
    return footer; 
} 


- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { 
if (section == [tableView numberOfSections] - 1) { 
    return 60.0; 
} else { 
    return 0.0; 
} 
} 
2

使用

if (section == yourArray.count -1) 
{ 
UIView *footer = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 540, 10)]; 
footer.backgroundColor = [UIColor clearColor]; 

UILabel *lbl = [[UILabel alloc]initWithFrame:footer.frame]; 
lbl.backgroundColor = [UIColor clearColor]; 
lbl.text = @"Your Text"; 
lbl.textAlignment = NSTextAlignmentCenter; 
[footer addSubview:lbl]; 
} 
return footer; 
+0

謝謝你的回答。去處理它 –

+0

其實爲什麼不修復底部? –

+0

我需要修復在底部可能的視圖 –

1

請嘗試,如果你想實現代碼如下的footerview使用這樣。

UIView *footer = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 540, 10)]; 
footer.backgroundColor = [UIColor clearColor]; 

UILabel *lbl = [[UILabel alloc]initWithFrame:footer.frame]; 
lbl.backgroundColor = [UIColor clearColor]; 
lbl.text = @"Your Text"; 
lbl.textAlignment = NSTextAlignmentCenter; 
[footer addSubview:lbl]; 
footer.backgroundColor = [UIColor blackColor]; 
self.tableView.tableFooterView = footer; 
2

試試這個,

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section 
{ 
    if (section == [tableView numberOfSections] - 1) { 
     return 10.0; 
    } else { 
     return 0.0; 
    } 
} 

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section    { 
     if (section == [tableView numberOfSections] - 1) { 

     UIView *footer = .. 
     .... 
     return footer; 
     } else { 
     return nil; 
     } 
} 

,或者你可以設置視圖頁腳泰伯維

UIView *footer = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 540, 10)]; 

.... 

[self.tableView setTableFooterView:footer]; 
+0

好的答案.. :) +1 – moosa0709

+0

感謝您的幫助.. –

+0

不客氣 – Akhilrajtr

相關問題