2012-11-19 13 views
0

我前4個ImageViews與4個UIButtons下他們,使用戶可以更改背景圖片。這是完美的。但是,然後我有4個UIButtons在應該調用電話號碼的ImageViews上。當我運行它時,它似乎不會調用按鈕,因爲當我單擊它時沒有任何反應。這裏是我的代碼:設置4個UIButtons撥打號碼的XCode

#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

確定按鈕位於圖片視圖的頂部嗎?如果沒有,請嘗試在IB中對其進行重新排序。 – Pandafox

+0

我會在'UIButtons'建議設置標籤和它'比較於didFinishPickingMediaWithInfo' –

回答

0

我會假設你在iOS模擬器,這是行不通的測試此。此代碼僅適用於真正的iOS設備。

+0

不錯,但你認爲它會在真實設備上工作? – wmichaelsen