【问题标题】:Set 4 UIButtons to call numbers XCode设置 4 个 UIButtons 来呼叫号码 XCode
【发布时间】:2012-11-19 22:01:25
【问题描述】:

我有前 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

怎么了?

【问题讨论】:

  • 您确定按钮位于图像视图的顶部吗?如果没有,请尝试在 IB 中重新排序。
  • 我建议在UIButtons 上设置标签并将其与didFinishPickingMediaWithInfo 中的标签进行比较

标签: iphone xcode


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-07
    • 2021-10-13
    • 1970-01-01
    相关资源
    最近更新 更多