-3

我是一名新的 iPhone 开发人员,我正在用 Objective-C 语言练习调用函数。有人可以帮助我吗?有我的节目详情。谢谢!

#import <UIKit/UIKit.h>

@interface TestingProgramViewController : UIViewController{
    NSTimer *aTimer;
    id getPic;
}
@end

#import "TestingProgramViewController.h"

@interface TestingProgramViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *testingPic;
@end

@implementation TestingProgramViewController

- (void) obtainPic:(NSString *)picName{
    NSString *urlLink = [[NSString alloc] initWithFormat:@"http://tdcctv.data.one.gov.hk/, %@!", picName];
    NSURL *url = [NSURL URLWithString:urlLink];
    UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL:url]];
    self.testingPic.image = image;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    [getPic obtainPic:@"H422F2.JPG"];
}
4

1 回答 1

1

您在构建 URL 时出错,请更改此行:

NSString *urlLink = [[NSString alloc] initWithFormat:@"http://tdcctv.data.one.gov.hk/, %@!", picName];

为了:

NSString *urlLink = [[NSString alloc] initWithFormat:@"http://tdcctv.data.one.gov.hk/%@", picName];

这样做我得到这个图像:

图片

编辑

调用方法时也有错误obtainPic,更改[getPic obtainPic:@"H422F2.JPG"];为:

[self obtainPic:@"H422F2.JPG"];
于 2013-04-13T13:53:04.657 回答