Ios UIImagePickerController和空白ImageView
我有一个非常奇怪的问题:我有一个TableViewController,它有两张图片和两个按钮。用户可以通过按钮更改图片 问题是当用户单击按钮时,UIActionSheet打开,用户从库中选择照片,然后在库中选择照片。UIActionSheet关闭,但我的ImageView中没有图片。。。它还是空白的。。。我的ImageView链接到@property 这是我的密码: .H文件:Ios UIImagePickerController和空白ImageView,ios,uitableview,uiimageview,uiimagepickercontroller,Ios,Uitableview,Uiimageview,Uiimagepickercontroller,我有一个非常奇怪的问题:我有一个TableViewController,它有两张图片和两个按钮。用户可以通过按钮更改图片 问题是当用户单击按钮时,UIActionSheet打开,用户从库中选择照片,然后在库中选择照片。UIActionSheet关闭,但我的ImageView中没有图片。。。它还是空白的。。。我的ImageView链接到@property 这是我的密码: .H文件: #import <UIKit/UIKit.h> @interface EditUserTableVie
#import <UIKit/UIKit.h>
@interface EditUserTableViewController : UITableViewController <UITextFieldDelegate, UIActionSheetDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate>
@property (weak, nonatomic) IBOutlet UIImageView *avatar;
@property (weak, nonatomic) IBOutlet UIImageView *coverPhoto;
- (IBAction)changeImage:(id)sender;
@end
.M文件:
#import "EditUserTableViewController.h"
typedef NS_ENUM(NSInteger, THPhotoType)
{
THPhotoTypeCoverPhoto = 10,
THPhotoTypeAvatarPhoto = 20
};
@interface EditUserTableViewController ()
@property (nonatomic, assign) THPhotoType selectedPhotoType;
@end
@implementation EditUserTableViewController
@synthesize coverPhoto, avatar;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (IBAction)changeImage:(id)sender {
if ([sender isKindOfClass:[UIButton class]]) {
UIButton *button = sender;
_selectedPhotoType = button.tag;
}
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Select Picture" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"From Library", @"From Camera", nil];
[sheet showInView:self.view];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex < 2) {
UIImagePickerController * imagePicker = [[UIImagePickerController alloc] init];
UIImagePickerControllerSourceType type;
switch (buttonIndex) {
case 0:
type = UIImagePickerControllerSourceTypePhotoLibrary;
break;
case 1:
type = UIImagePickerControllerSourceTypeCamera;
break;
default:
break;
}
imagePicker.sourceType = type;
imagePicker.delegate = self;
[self presentViewController:imagePicker animated:YES completion:^{ }];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
switch (_selectedPhotoType) {
case THPhotoTypeCoverPhoto:
coverPhoto.image = [info objectForKey:UIImagePickerControllerOriginalImage];
break;
case THPhotoTypeAvatarPhoto:
avatar.image = [info objectForKey:UIImagePickerControllerOriginalImage];
break;
default:
break;
}
[self dismissViewControllerAnimated:YES completion:^{ }];
}
@end
将图像设置为图像视图时出现问题。请尝试此操作
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
switch (_selectedPhotoType) {
case THPhotoTypeCoverPhoto:
self.coverPhoto.image = [info objectForKey:UIImagePickerControllerOriginalImage];
break;
case THPhotoTypeAvatarPhoto:
self.avatar.image = [info objectForKey:UIImagePickerControllerOriginalImage];
break;
default:
break;
}
[self dismissViewControllerAnimated:YES completion:^{ }];
}好的,我是%^&*&^
这是我的按钮标签的问题
问题解决了