简体   繁体   English

如何使单元格中的按钮仅可选择?

[英]How can I make only the button selectable in a cell?

I have a Cell with lots of Labels and a Button.我有一个带有很多标签和一个按钮的单元格。

I want to make cell's color blue and make only the button selectable, not the cell.我想让单元格的颜色变为蓝色,并且只能选择按钮,而不是单元格。

The button should have its own color.按钮应该有自己的颜色。

How can I do this using with xCode and the IPhone SDK?我如何使用 xCode 和 iPhone SDK 来做到这一点?

implement the following method in your UITableViewController:在您的 UITableViewController 中实现以下方法:

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath

Then return nil for any cell that you do not want selectable (Your cells with buttons).然后为您不想选择的任何单元格(您的带按钮的单元格)返回 nil。 You can get additionaly explanation from the UITableViewDelegate protocol reference.您可以从 UITableViewDelegate 协议参考中获得额外的解释。

From the UItableViewDelegate protocol reference:来自 UItableViewDelegate 协议参考:

-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath -(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath

Parameters tableView A table-view object informing the delegate about the impending selection.参数tableView 表视图 object 通知代表即将进行的选择。

indexPath An index path locating the row in tableView. indexPath在 tableView 中定位行的索引路径。

Return Value An index-path object that confirms or alters the selected row.返回值确认或更改所选行的索引路径 object。 Return an NSIndexPath object other than indexPath if you want another cell to be selected.如果要选择另一个单元格,则返回 indexPath 以外的 NSIndexPath object。 Return nil if you don't want the row selected.如果您不想选择该行,则返回 nil。

Discussion This method is not called until users touch a row and then lift their finger;讨论直到用户触摸一行然后抬起手指时才会调用此方法; the row isn't selected until then, although it is highlighted on touch-down.该行直到那时才被选中,尽管它在触地时突出显示。 You can use UITableViewCellSelectionStyleNone to disable the appearance of the cell highlight on touch-down.您可以使用 UITableViewCellSelectionStyleNone 禁用触摸时单元格突出显示的外观。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM