我被要求制作一个应用程序,为他们的猫提供随机字幕。我有 2 个问题,我一步一步按照教程进行操作,但没有任何效果。1. 拍摄或选择图片时,它不会显示在 UIImageView 中,故事板中的每件事都喜欢我只是不明白。另外,我制作了一个 IBAction,它在其中生成随机标题,并且在按下按钮时工作正常,无论如何,当拍摄或选择图片时,标题会自动显示吗?这是我在 .M 文件中的代码。我是制作应用程序的初学者。
#import "Generator.h"
@interface Generator ()
@end
@implementation Generator
-(IBAction)TakePhoto{
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
[picker setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentViewController:picker animated:YES completion:NULL];
}
-(IBAction)ChooseExisting{
picker2 = [[UIImagePickerController alloc] init];
picker2.delegate = self;
[picker2 setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:picker2 animated:YES completion:NULL];
}
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
image = [info objectForKey:UIImagePickerControllerOriginalImage];
[self dismissViewControllerAnimated:YES completion:NULL];
}
-(void) imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismissViewControllerAnimated:YES completion:NULL];
}
-(IBAction)Back{
[self dismissViewControllerAnimated:YES completion:NULL];
}
-(IBAction)random {
int text = rand() % 10;
switch (text) {
case 0:
textview.text = @"I'd Say About Average";
break;
case 1:
textview.text = @"Happy but Hideous";
break;
case 2:
textview.text = @"Furrific";
break;
case 3:
textview.text = @"Cuddly";
break;
case 4:
textview.text = @"Abby Normal";
break;
case 5:
textview.text = @"Purrty";
break;
case 6:
textview.text = @"Yuck";
break;
case 7:
textview.text = @"Glowing";
break;
case 8:
textview.text = @"AWWWWWW";
break;
case 9:
textview.text = @"The Cutest";
break;
default:
break;
}
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
任何帮助都可以。我的 SDK 是 iOS 6.1