我被要求制作一个应用程序,随机提供关于他们的猫的标题。我有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
答案 0 :(得分:0)
图片已自动释放。在imageView超出范围之前设置它,或保留它。如果你把它连接到任何东西,它应该留在记忆中并显示。