【问题标题】:button is not run Xcode按钮未运行 Xcode
【发布时间】:2015-09-03 06:52:23
【问题描述】:

我在视图控制器中有这段代码,但拨号按钮没有运行,图像视图没有出现任何东西

    //
//  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

你能帮帮我吗

【问题讨论】:

    标签: ios objective-c


    【解决方案1】:

    在您的情况下,字符串中有空格不会将字符串转换为 url @" http://93.95.207.34/easybuy.com/car/car2.png " 所以实际上并没有创建图像。

    对于 ImageView 使用此代码

    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];   
    

    对于调用过程使用这个

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

    并确保您已将图像视图和 uibutton 操作附加到 interfaceBuilder(故事板或 .xib)

    【讨论】:

    • 这在 interfaceBuilder 上是真的 ???? {@interface ViewController : UIViewController{ IBOutlet UIImageView *imageview; __weak IBOutlet UIButton *愈伤组织; } @end}
    • 所以在设备上检查它而不是模拟器调用在模拟器上不起作用,你的问题将得到解决
    【解决方案2】:

    对于 ImageView,您添加了空格。你应该修剪那个空间。另一件事是你应该在编码后调用 url 。和平滑的图像加载,您应该使用dispatch_get_global_queue 在后台队列中调用 url。检查(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];
    

    电话联系

    NSURL *url = [NSURL URLWithString:[NSString  stringWithFormat:@"telprompt://00962796880853"]];
    
    if ([[UIApplication sharedApplication] canOpenURL:url]) {
        [[UIApplication sharedApplication] openURL:url];
    } else
    {
        //Call functionality not available.
    }
    

    【讨论】:

      【解决方案3】:

      希望对你有帮助

      在真机上查看

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-08-27
        • 2018-04-15
        • 1970-01-01
        • 2016-05-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多