我想制作一个随机文本生成器,我知道如何做一个普通的,但在这种情况下我无法让它工作。因此,我拍摄或选择图片的代码,然后将其显示在不同的视图控制器上,我想在每次拍摄照片时将最后一个视图控制器上的标签设置为随机句子。我不知道我是否正确解释了自己。这是我拥有的代码:
//ViewController.m
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"CameraSegue"] || [segue.identifier isEqualToString:@"LibrarySegue"])
{
UIImagePickerController *controller = [segue destinationViewController];
controller.sourceType = [segue.identifier isEqualToString:@"LibrarySegue"] ? UIImagePickerControllerSourceTypePhotoLibrary : UIImagePickerControllerSourceTypeCamera;
controller.delegate = self;
}
else if([segue.identifier isEqualToString:@"ShowImageViewController"]){
UIImage *image = (UIImage*)sender;
ShowImageViewController *viewController = segue.destinationViewController;
viewController.pickedImage = image;
UILabel *label = (UILabel *) sender;
ShowImageViewController *vc = segue.destinationViewController;
vc.cap = label;
//I tried to set the label here
label.text = @"Hello";
}
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[self dismissViewControllerAnimated:YES completion:nil];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
[self dismissViewControllerAnimated:YES completion:^{
picker.delegate = nil;
[self performSegueWithIdentifier:@"ShowImageViewController" sender:image];
}];
}
//SeconViewController.h
@property(nonatomic, strong) UIImage *pickedImage;
@property (weak, nonatomic) IBOutlet UIImageView *pickedImageView;
@property(nonatomic, retain) IBOutlet UILabel *cap;
//SecondViewController.m
-(void)viewWillAppear:(BOOL)animated{
self.pickedImageView.image = self.pickedImage;
}