这里的困境是:我想创建一个自定义 editingAccessoryView
包含两个按钮用于我的股票UITableViewCell
.我想使用 Storyboard来实现这一点。到目前为止,我已经按照 here 概述的步骤进行操作。 , here和 here .我似乎无法让它工作。我得到的最接近的是当我创建类型为 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/