Question

I was asked to make an app that gave random captions about their cat. I have 2 problems and I followed tutorials step by step and nothing worked. 1. When ever a picture is taken or selected, it does not show up in the UIImageView, every thing is liked up in the storyboard I just don't get it. Also, I have an IBAction made where it makes the random caption and it works fine when its pressed by a button, is there anyway where the caption will display automaticly when a picture is either taken or selected? Here is my Code in the .M file. Im a beginner when it comes to makeing apps.

#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

any help will do. my SDK is iOS 6.1

Was it helpful?

Solution

image is autoreleased. Set your imageView before it goes out of scope, or retain it. If you have it hooked up to anything, it should stay in memory and show.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top