0

我有两个按钮没有执行它们被编程执行的 IBAction。我在 Interface Builder 中正确连接了它们,但是当我在模拟器或手机上单击它们时,它们不会执行任务。没有崩溃,什么都没有。这是我的代码

MapDetailInfo.h:

@interface MapDetailInfo : UIViewController {

IBOutlet UILabel *name;
IBOutlet UITextView *address;
NSString * nameText;
NSString * addressText;
NSString * stringOne;
NSString * stringTwo;


IBOutlet UILabel *phoneNumber;

}

@property (retain, nonatomic) IBOutlet UILabel *name;
@property (retain, nonatomic) IBOutlet UITextView *address;
@property (nonatomic, copy) NSString * nameText;
@property (nonatomic, copy) NSString * addressText;
@property (retain, nonatomic)  NSString * stringOne;
@property (retain, nonatomic)  NSString * stringTwo;
@property (retain, nonatomic) IBOutlet UILabel *phoneNumber;

- (IBAction)callPhone:(id)sender;
- (IBAction)getDirections:(id)sender; 


@end

MapDetailInfo.m:

@implementation MapDetailInfo
@synthesize name, address, nameText, addressText, phoneNumber, stringTwo, stringOne;
- (void)viewDidLoad
{
[super viewDidLoad];
NSArray *myWords = [addressText componentsSeparatedByCharactersInSet:
                    [NSCharacterSet characterSetWithCharactersInString:@"("]
                    ];

stringOne = [myWords objectAtIndex:1];
stringTwo = @"("; 


stringTwo = [stringTwo stringByAppendingString:stringOne];


self.name.text = nameText;
self.address.text = [myWords objectAtIndex:0];
self.phoneNumber.text = stringTwo; 

  UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self 
           action:@selector(callPhone:)
 forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"Call Shop" forState:UIControlStateNormal];
button.frame = CGRectMake(104.0, 332.0, 160.0, 40.0);
[self.view addSubview:button];


}


- (IBAction)callPhone:(id)sender {

NSString *URLString = [@"tel://" stringByAppendingString:stringTwo];

NSURL *URL = [NSURL URLWithString:URLString];

[[UIApplication sharedApplication] openURL:URL];
}

- (IBAction)getDirections:(id)sender {
 [[UIApplication sharedApplication] openURL:
 [NSURL URLWithString:[NSString stringWithFormat:@"http://maps.google.com/maps?saddr=Current    Location&daddr=%@",self.address.text]]];    
}

我正在从地图中的注释中提取此视图。对于这两个不执行任务的按钮,一切正常。任何帮助将非常感激。谢谢!

4

2 回答 2

1

按钮不起作用的原因是 URL 不正确。如果您遇到同样的问题,请确保您的电话号码 URL 是:

@"tel://5555555"

我的里面有括号和破折号,这就是为什么它不会拉起来。我的谷歌网址也有错误。

谢谢!

于 2011-07-12T18:49:53.443 回答
-1

UIButton在您的代码中没有看到任何内容。你用过它们吗?

编辑:

我曾建议您为此使用按钮。是的,您仍然可以使用标签并按照相同的过程调用方法。

您连接插座的方式一定有问题。

我建议您遵循此 Youtube 链接的教程 - 4、5 和 6。 http://www.youtube.com/watch?v=B7jB0D3Y7Ws&feature=relmfu

于 2011-07-06T15:53:41.177 回答