我是一名新的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"];
}
答案 0 :(得分:1)
您在构建网址时出错,请更改此行:
NSString *urlLink = [[NSString alloc] initWithFormat:@"http://tdcctv.data.one.gov.hk/, %@!", picName];
有:
NSString *urlLink = [[NSString alloc] initWithFormat:@"http://tdcctv.data.one.gov.hk/%@", picName];
这样做我得到这个图像:
image http://tdcctv.data.one.gov.hk/H422F2.JPG
修改强>:
调用方法obtainPic
时也会出错,请更改[getPic obtainPic:@"H422F2.JPG"];
:
[self obtainPic:@"H422F2.JPG"];