开发者

Faulty button makes the phonecall before pressing it

开发者 https://www.devze.com 2023-03-08 05:30 出处:网络
The code works but the app is calling the string without the press of the button. As soon as I reach the particular page of the app, it is bypassing everything (Other buttons, map views, etc) and make

The code works but the app is calling the string without the press of the button. As soon as I reach the particular page of the app, it is bypassing everything (Other buttons, map views, etc) and makes the call...

The code I'm using is:

   - (void)loadNo2 {
        UIButton 开发者_高级运维*no2 = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        [no2 setTitle:@"2108642700" forState:UIControlStateNormal];
        [no2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [no2 setBackgroundColor:[UIColor blackColor]];
        [no2 setFrame:CGRectMake(84, 260, 152, 31)];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://1234567890"]];
        [self addSubview:no2];
    }

What is wrong with it???


This line brings up the dialog to dial

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://1234567890"]];

You didn't add it as a button action -- you are just calling it.

Replace that line with this:

  [no2 addTarget:self 
          action:@selector(onNo2Touch) 
forControlEvents:UIControlEventTouchUpInside];

And add this:

-(void) onNo2Touch:(id) sender {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://1234567890"]];
}


Looks like you've called the openURL from the method that creates the button. You should put the call to UIApplication sharedApp... (i.e.

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://1234567890"]]; ) inside the method called from the action (that is mapped to the button) .

0

精彩评论

暂无评论...
验证码 换一张
取 消