我有前4个ImageViews,下面有4个UIButtons,因此用户可以更改背景图片。这非常有效。但是我在ImageViews上有4个UIButton,它们应该拨打电话号码。当我运行它时似乎没有调用按钮,因为当我点击它时没有任何反应。这是我的代码:
#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
怎么了?
答案 0 :(得分:0)
我将假设你在iOS模拟器上测试它,这将无法正常工作。此代码仅适用于真正的iOS设备。