IBActions不起作用

时间:2011-07-06 15:51:07

标签: iphone ibaction

我有两个按钮没有执行他们编程要执行的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]]];    
}

我从地图中的注释中提取此视图。一切都完美地接受这两个不执行任务的按钮。任何帮助将非常感激。谢谢!

2 个答案:

答案 0 :(得分:1)

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

@"tel://5555555"

我的括号和冲刺在我的内部,这就是为什么它不会拉起来。我的谷歌网址也有错误。

谢谢!

答案 1 :(得分:-1)

我在代码中看不到任何UIButton。你用过它们吗?

修改

我曾建议您使用按钮,这是特定目的。是的,您仍然可以使用标签并按照相同的步骤调用方法。

连接插座的方式存在一些问题。

我建议您按照Youtube链接的教程 - 4,5和6进行操作。 http://www.youtube.com/watch?v=B7jB0D3Y7Ws&feature=relmfu