2013-07-16 30 views
0

尝试识别选择TableViewCell。它们是静态单元,不需要任何滚动。我需要实现UITableView吗?有没有一种方法可以在不实现TableView和关联方法的情况下向TableViewCell添加操作?自定义TableViewCell作为没有UITableView的按钮

+0

静态单元格只在UITableViewController中工作,它已经包含了UITableView。如果你不想使用UITableView,为什么不使用UIButton。 – Rick

回答

0

目前还不清楚你想要什么,或者你为什么想要不使用表格视图。但是,如果您实现了控制静态表视图的UITableViewController,则不必实现任何常用的数据源方法。你可以实现委托方法tableViewDidSelectRowAtIndexPath:,并使用它来提供选择单元格时的动作。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    if (indexPath.row == 0) 
     //do some action; 
    if (indexPath.row == 1) 
     //do some other action; 
    //etc. 
} 
0

UITableViewCell是UIView的子类,因此您可以将它作为子视图添加到任何视图。但UITableViewCell被设计为在UITableView中使用,如果不使用UITableView,则无法使其完美工作。为什么不使用UITableView来包含单元格?您可以设置tableview.scrollEnabled = NO;使其变为静态。