2013-03-14 150 views
0

我被要求制作一个应用程序,提供关于他们的猫的随机标题。我有两个问题,我一步一步跟着教程,没有任何工作。 1.当拍摄或选择一张照片时,它不会显示在UIImageView中,故事板中的每一个东西都会被喜欢,我只是不明白。另外,我在制作随机标题的地方制作了一个IBAction,当它按下按钮时,它可以正常工作,无论如何,当图片被拍摄或选择时,标题会自动显示在哪里?这是我的.M文件中的代码。当谈到制作应用程序时,我是一名初学者。iPhone标题摄像头,imageview不显示拍摄的照片

#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

您上面的代码没有imageView。 你想在这里做什么? image = [info objectForKey:UIImagePickerControllerOriginalImage]; – 2013-03-14 22:05:24

+0

“image = [info objectForKey:UIImagePickerControllerOriginalImage];”什么是形象?它应该是'urImageView.image = ...' – 7usam 2013-03-14 22:05:55

+0

什么是meathod设置拍摄到imageview我有吗? – goofballcent 2013-03-15 01:03:48

回答

0

图像是自动释放的。将imageView设置为超出范围之前,或保留它。如果你把它连接到任何东西,它应该留在记忆和展示。

相关问题