iphone - 自定义 UITableViewCell 编辑AccessoryView?

标签 iphone ios xcode ios4

这里的困境是:我想创建一个自定义 editingAccessoryView包含两个按钮用于我的股票UITableViewCell .我想使用 Storyboard来实现这一点。到目前为止,我已经按照 here 概述的步骤进行操作。 , herehere .我似乎无法让它工作。我得到的最接近的是当我创建类型为 UIView 的 xib 时。 , 将类(class)设置为我的 UIViewController包含 UITableView并将其绑定(bind)到我的IBOutlet , 但在 cellForRowAtIndexPath它是 nil .

事实是,我想我只需要知道如何创建 View 然后将其映射到 editAccessoryView ;从那里我相信我可以弄清楚如何添加按钮并映射相应的IBAction .谁能提供一些分步说明或教程链接?

最佳答案

我用以下代码自己解决了这个问题:

    UIView *editingCategoryAccessoryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 120, 35)];

    UIButton *addCategoryButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [addCategoryButton setTitle:@"Add" forState:UIControlStateNormal];
    [addCategoryButton setFrame:CGRectMake(0, 0, 50, 35)];
    [addCategoryButton addTarget:self action:@selector(addCategoryClicked:withEvent:) forControlEvents:UIControlEventTouchUpInside];

    UIButton *removeCategoryButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [removeCategoryButton setTitle:@"Remove" forState:UIControlStateNormal];
    [removeCategoryButton setFrame:CGRectMake(55, 0, 65, 35)];
    [removeCategoryButton addTarget:self action:@selector(removeCategoryClicked:withEvent:) forControlEvents:UIControlEventTouchUpInside];

    [editingCategoryAccessoryView addSubview:addCategoryButton];
    [editingCategoryAccessoryView addSubview:removeCategoryButton];
    cell.editingAccessoryView = editingCategoryAccessoryView;

如您所见,我创建了一个新的 UIView以编程方式并通过 addSubview 添加两个按钮然后将其分配给 editingAccessoryView .

关于iphone - 自定义 UITableViewCell 编辑AccessoryView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20684330/

相关文章:

iphone - 在 iPhone 上使用 CHDataStructures.framework

ios - 界面构建器上的自定义格式化程序的用途是什么?

ios - 容器 View 页面 Controller 被裁剪而不是调整大小

ios - 获取 ALAssetGroup 中的照片和视频的计数

ios - 该应用程序在有效负载 : hidden 中引用了非公共(public)选择器

iphone - 升级xcode使用的sqlite3版本?

iphone - 我怎样才能让它在 android/iphone 上播放视频?

iOS:在 iPad 应用程序中绘制可编辑图形,使用 html5

objective-c - iOS/Objective C- 来自 NSMutableURLRequest 的空响应

xcode - 在每个功能/每个代码块的基础上启用 SSE4 的正确方法?