0

我有前 4 个 ImageView,下面有 4 个 UIButton,因此用户可以更改背景图片。这完美无缺。但是后来我在 ImageViews 上有 4 个 UIButtons 应该拨打电话号码。当我运行它时,它似乎没有调用该按钮,因为当我单击它时没有任何反应。这是我的代码:

#import "ViewController.h"

@interface ViewController ()
{
UIImagePickerController *imagePickerController;
UIImagePickerController *imagePickerController2;
UIImagePickerController *imagePickerController3;
UIImagePickerController *imagePickerController4;
}

@end

@implementation ViewController
@synthesize firstImageView, secondImageView, thirdImageView, fourthImageView;
- (void)viewDidLoad
{
[super viewDidLoad];

}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];

}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image1 = [info objectForKey:UIImagePickerControllerOriginalImage];

NSData *data = UIImagePNGRepresentation(image1);
NSString *myGrabbedImage = @"myGrabbedImage.png";
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [path objectAtIndex:0];
NSString *fullPathToFile = [documentDirectory stringByAppendingPathComponent:myGrabbedImage];

[data writeToFile:fullPathToFile atomically:YES];

if (picker == imagePickerController) {
    [[self firstImageView]setImage:image1];
} else if (picker == imagePickerController2) {
    [[self secondImageView]setImage:image1];
} else if (picker == imagePickerController3) {
    [[self thirdImageView]setImage:image1];
} else {
    [[self fourthImageView]setImage:image1];
}

[self dismissViewControllerAnimated:YES completion:nil];

}

- (IBAction)firstChangeButton:(id)sender
{
imagePickerController = [[UIImagePickerController alloc]init];
[imagePickerController setDelegate:self];
[imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:imagePickerController animated:YES completion:nil];

}
- (IBAction)secondChangeButton:(id)sender
{
imagePickerController2 = [[UIImagePickerController alloc]init];
[imagePickerController2 setDelegate:self];
[imagePickerController2 setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:imagePickerController2 animated:YES completion:nil];

}
- (IBAction)thirdChangeButton:(id)sender
{
imagePickerController3 = [[UIImagePickerController alloc]init];
[imagePickerController3 setDelegate:self];
[imagePickerController3 setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:imagePickerController3 animated:YES completion:nil];

}
- (IBAction)fourthChangeButton:(id)sender
{
imagePickerController4 = [[UIImagePickerController alloc]init];
[imagePickerController4 setDelegate:self];
[imagePickerController4 setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:imagePickerController4 animated:YES completion:nil];

}



- (IBAction)callFirst:(id)sender
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:0739421700"]];
}

- (IBAction)callSecond:(id)sender
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:073942100"]];
}

- (IBAction)callThird:(id)sender
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:0739421700"]];
}

- (IBAction)callFourth:(id)sender
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:0739421700"]];

}
@end

怎么了?

4

1 回答 1

0

我将假设您正在 iOS 模拟器上对此进行测试,但这是行不通的。此代码仅适用于真正的 iOS 设备。

于 2012-11-19T22:06:33.210 回答