2010-11-23 102 views
1

我有一個表格視圖,其中數字單元格不固定,並且會不斷變化。我必須在桌腳的最後一個單元格後顯示兩個動作按鈕。如何在我的最後一個細胞後正確放置它們?我知道最後一個單元格和這些按鈕之間的像素間距。任何代碼示例都會非常有用。桌面頁腳視圖中的按鈕位置

+0

UITableView是Cocoa Touch的一部分,而不是Cocoa。 – 2010-11-23 05:39:49

+0

我的不好。感謝您糾正我! – Abhinav 2010-11-23 05:47:43

回答

0

您可以隨時將兩個按鈕添加到最終的單元格。

- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section { 
    return [myCellDataArray count]+1; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    UITableViewCell *cell = nil; 
    if (indexPath.row > [myCellDataArray count]) { 
    cell = [tableView dequeueReusableCellWithIdentifier:@"Button Cell"]; 
    if (cell == nil) { 
     UIButton *firstButton = [[UIButton alloc] init]; 
     //customization 
     UIButton *secondButton = [[UIButton alloc] init]; 
     //customization 

     [cell addSubView:firstButton]; 
     [cell addSubView:firstButton]; 
    } 
} else { 
    // normal stuff 
} 

如果你想定製你需要設置它的標籤,以獨特的東西,即firstButton.tag = 100現有的按鈕,然後通過firstButton = (UIButton *)[cell viewWithTag:100];設置firstButton。確保你定義了firstButton,以便它在範圍內!

希望這會有所幫助!

1

你有沒有試過將它們粘在一個視圖中並將其設置爲頁腳視圖?

在添加之前,您需要給它正確的高度;寬度會自動設置爲表格的寬度。將其設置爲合理的寬度(例如320)並使用自動調整大小或使用自定義UIView子類並實現-layoutSubviews。