是否可以像按钮一样使用 tableView 单元格?在我的应用程序中,我想要一个有 4 行的 TableView ,每行都有标签。我想要的是当我触摸一行时,table tableview 单元格应该像按钮一样 react (执行操作并且突出显示背景)?那可能吗?我怎样才能做到这一点?谢谢。
最佳答案
非常简单,委托(delegate)方法将被调用 didSelectRowAtIndexPath 在那里你可以得到在哪个部分点击了哪一行,你可以执行进一步的操作。
例如
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// deselect
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if(indexPath.row == 0){
LoginFormViewController *vController = nil;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
vController = [[LoginFormViewController alloc] initWithNibName:@"LoginFormViewController_ipad" bundle:nil];
}else {
vController = [[LoginFormViewController alloc] initWithNibName:@"LoginFormViewController" bundle:nil];
}
[self.navigationController pushViewController:vController animated:YES];
[vController release];
}
}
关于iphone 开发 : using tableview cells as a button,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12330577/