-2

I have this code in view controller but the button for dial number is not run and the image view not appear any thing

    //
//  ViewController.m
//  EasyBuy
//
//  Created by Moments on 9/2/15.
//  Copyright (c) 2015 Moments. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    imageview.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@" http://93.95.207.34/easybuy.com/car/car2.png "]]];

    // Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)callus:(id)sender {

    [[ UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:00962796880853"]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

can you help me

Popeye
  • 11,839
  • 9
  • 58
  • 91
Hamza Abdullah
  • 181
  • 1
  • 4
  • 18

3 Answers3

2

in your case you have spaces in string that will not convert string to url @" http://93.95.207.34/easybuy.com/car/car2.png " So image didnt created actually.

For ImageView use this code

NSURL *url = [NSURL URLWithString:@"http://93.95.207.34/easybuy.com/car/car2.png"];

NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:data];

[imageview setImage:image];   

And for calling procedure use this

NSString *phoneStr = @"telprompt://00962796880853";
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneStr]];

And make sure you have attached both the image view and uibutton action to interfaceBuilder(storyboard or .xib)

baydi
  • 1,003
  • 6
  • 11
  • this is true on interfaceBuilder ???? {@interface ViewController : UIViewController{ IBOutlet UIImageView *imageview; __weak IBOutlet UIButton *callus; } @end} – Hamza Abdullah Sep 03 '15 at 07:11
  • 1
    So check it on device instead simulator call doesnot work on simulator , your problem will be solved – baydi Sep 03 '15 at 07:15
1

For ImageView you have added blank space. You should trim that space. and Another thing is you should call url after Encoding it. and smooth image loading you should call url in background queue using dispatch_get_global_queue. Check (loading images from a background thread using blocks)

NSURL *url = [NSURL URLWithString:[@"http://93.95.207.34/easybuy.com/car/car2.png" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSData *dataIMG = [NSData dataWithContentsOfURL:url];
imageview.image = [UIImage imageWithData:dataIMG];

For Telephone

NSURL *url = [NSURL URLWithString:[NSString  stringWithFormat:@"telprompt://00962796880853"]];

if ([[UIApplication sharedApplication] canOpenURL:url]) {
    [[UIApplication sharedApplication] openURL:url];
} else
{
    //Call functionality not available.
}
Community
  • 1
  • 1
ChintaN -Maddy- Ramani
  • 5,156
  • 1
  • 27
  • 48
0

hope it help you

check it on real device

[[ UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://00962796880853"]];
Garry
  • 407
  • 2
  • 15