从UITableViewCell iOS打开相机 [英] open camera from UITableViewCell iOS
问题描述
我有一个UITableView和一个UITableViewCell。在每个UITableViewCell中,我要打开图库或单击图像。我通常会像这样显示UIImageviewController
I have a UITableView and a UITableViewCell. In every UITableViewCell I want to open gallery or click an image. I normally present UIImageviewController like
- (IBAction)takePhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
如何从单元格中显示?
Misha:)
推荐答案
正确的解决方案是使用正确的MVC设计。让您的自定义单元格为其自己的委托方法定义协议。将表视图控制器设置为每个单元格的委托。
The proper solution is to use proper MVC design. Have your custom cell define a protocol for its own delegate methods. Setup your table view controller to be each cell's delegate.
协议方法之一就是要求委托代表其代表视图控制器的方法。
One of the protocol methods would be a method asking the delegate to present a view controller on its behalf.
您的单元格协议应具有以下方法:
Your cell protocol would have a method such as:
- (void)cell:(CustomTableViewCell *)cell presentViewController:(UIViewController *)controller;
自定义单元格的 takePhoto
方法,您可以执行某些操作像这样:
Your custom cell's takePhoto
method you do something like this:
- (IBAction)takePhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self.delegate cell:self presentViewController:picker];
}
然后您的表视图控制器将实现该方法:
Then your table view controller would implement the method:
- (void)cell:(CustomTableViewCell *)cell presentViewController:(UIViewController *)controller {
[self presentViewController:controller animated:YES completion:NULL];
}
这篇关于从UITableViewCell iOS打开相机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!