2010-11-23 98 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。