iphone 开发 : using tableview cells as a button

标签 iphone objective-c ios uitableview uibutton

是否可以像按钮一样使用 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/

相关文章:

ios - 如何在 Xcode 8 中创建没有 LaunchScreen 的空应用程序

ios - Tl.xcodeproj 链接框架 'Pods_Tl.framework' 缺少此目标 : armv7 所需的一个或多个架构

ios - 快速更改 titleTextAttribute

ios - 如何在 Azure 中调试测试发送?

ios - 如果两个 iBeacon 靠得很近,一个信号能否在传输到设备 (iPhone) 时覆盖另一个信号

iphone - CLLocationManager - iPhone 应用程序中的自定义位置管理器

iphone - 使用 iOS 5 在 iPhone 中使用 JSON 数据

objective-c - cocoa 和缓存

ios - 带有 UITabBarController 的 ABPeoplePickerNavigationController 在 iOS8 中未正确显示

ios - 使用搜索在 App 内启动 iTunes Store