Ios 从UITableView单元中打开相机
我在一个定制的单元格中有一个按钮,用来打开相机拍照 我想了两种方法,但都没办法。 第一个是从单元格内打开UIImagePickerController的实例。看来我不能打电话了Ios 从UITableView单元中打开相机,ios,uitableview,uiimagepickercontroller,Ios,Uitableview,Uiimagepickercontroller,我在一个定制的单元格中有一个按钮,用来打开相机拍照 我想了两种方法,但都没办法。 第一个是从单元格内打开UIImagePickerController的实例。看来我不能打电话了 [self presentViewController...]; 在牢房里。是这样吗 由于这个“结果”,我想把打开UIImagePickerController的方法放在TableViewController中,然后从单元格(按钮所在的位置)中调用这个方法,方法如下 [super openCamera]; 或者使Ta
[self presentViewController...];
在牢房里。是这样吗
由于这个“结果”,我想把打开UIImagePickerController的方法放在TableViewController中,然后从单元格(按钮所在的位置)中调用这个方法,方法如下
[super openCamera];
或者使TableViewController成为单元格的委托,以使其能够调用该方法
这些想法是否朝着正确的方向发展?你推荐什么?多谢各位 好吧,我想了些办法,但我还是想知道是否可以更容易些。 以下是我找到的解决方案: 在我添加的自定义单元格中
@property (nonatomic, assign) id adminController;
然后在tableViewController中,我自定义了以下方法,以使用我创建的自定义单元格,并将tableViewController设置为“admin”
所以我终于可以打电话了
[self.adminController performSelector:@selector(openCamera)];
这是一个老问题,但我想让我的老问题也得到回答,所以。。。是的,使用块有一种更简单的方法: 首先,在UITableViewCell接口中声明一个公共方法:
@interface YourCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UIButton *button;
- (void)setDidTapButtonBlock:(void (^)(id sender))didTapButtonBlock;
@end
在UITableViewCell子类实现文件中,声明具有copy属性的私有属性
#import "YourCell.h"
@interface YourCell ()
@property (copy, nonatomic) void (^buttonTappedBlock)(id sender);
@end
在UITableViewCell构造函数中添加UIControl的目标和操作,并实现选择器方法
- (void)awakeFromNib {
[super awakeFromNib];
[self.button addTarget:self
action:@selector(didTapButton:)
forControlEvents:UIControlEventTouchUpInside];
}
- (void)didTapButton:(id)sender {
if (buttonTappedBlock) {
buttonTappedBlock(sender);
}
}
最后在控制器中的tableView:cellforrowatinexpath:method中实现块代码
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
YourCell *cell = (YourCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier
forIndexPath:indexPath];
[cell buttonTappedBlock:^(id sender) {
NSLog(@"%@", item[@"title"]);
}];
return cell;
}
有关块中的详细信息,您可以阅读在何处写入此行[self.adminController performSelector:@selector(openCamera)]??
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
YourCell *cell = (YourCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier
forIndexPath:indexPath];
[cell buttonTappedBlock:^(id sender) {
NSLog(@"%@", item[@"title"]);
}];
return cell;
}