【问题标题】:button that takes pictures within expanding uitableViewCell在展开的 uitableViewCell 内拍照的按钮
【发布时间】:2014-12-16 01:51:37
【问题描述】:

好的,我有一个带有自定义扩展单元格的 UITableView。单元格有一个 .xib .m 和 .h 。我正在尝试使用一个按钮来打开相机以拍照并将其保存在按下按钮的单元格中。但它不工作。我已经研究了过去几天,找不到任何解决方案。这是我在扩展单元格的 .m 文件中的代码:

-(void)awakeFromNib {
    // Initialization code

[scroller setScrollEnabled:YES];

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTitle:@"+" forState:UIControlStateNormal];
[button sizeToFit];
[button setBackgroundColor:[UIColor redColor]];

button.center = CGPointMake( 25, 50);

[button addTarget:self action:@selector(buttonPressed:)forControlEvents:UIControlEventTouchUpInside];

[self addSubview:button];
}

- (IBAction)buttonPressed:(UIButton *)button {

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[picker setDelegate:self];
picker.allowsImageEditing = NO;
//[self presentModalViewController:picker animated:YES];
//[self presentViewController:picker animated:YES completion:nil];
picker.showsCameraControls = YES;
}

我一直在从 buttonPressed 方法注释掉的行中收到错误,它说 "no visible @interface for 'ExpandingCell' declares the selector 'presentModalExpandingCell:animated:'" 我已经尝试了它们(不是同时)并得到了相同的错误。我是 iOS 编程的新手,不确定这意味着什么,所以我不知道从哪里开始修复它。

我应该在 tableview 所在的 ViewController 中而不是在扩展单元格中尝试这个吗? 任何帮助或指导表示赞赏。先感谢您。

【问题讨论】:

    标签: ios objective-c iphone xcode uitableview


    【解决方案1】:

    您应该将视图控制器传递到单元格中,只需分配它,然后在按钮按下操作中调用 presentModalExpandingCell:animated 与此视图控制器。

    【讨论】:

    • 我不确定你的意思。你能说得更详细些吗?
    • 在你的单元格类中,你添加一个属性来分配视图控制器(包含你的表格视图)。然后在你现在的方法中,你可以使用这个视图控制器。可以保留视图控制器是重要的,否则会导致保留循环。
    • 所以在单元格 .h 文件中放入“@property (strong, nonatomic) UIViewController *ViewController4;”?我尝试使用 viewcontrollers 名称而不是“UIViewController”并得到另一个错误。
    猜你喜欢
    • 2014-01-13
    • 2012-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多