Iphone 从网站加载图像
我正在尝试创建一个简单的应用程序,它将显示每天发布的图像。但是,图像的名称每天都在变化 这是我到目前为止所拥有的Iphone 从网站加载图像,iphone,objective-c,ipad,Iphone,Objective C,Ipad,我正在尝试创建一个简单的应用程序,它将显示每天发布的图像。但是,图像的名称每天都在变化 这是我到目前为止所拥有的 --- .h file { UIWebView *webView; } @property (nonatomic, strong) IBOutlet UIWebView *webView; @end --- .m file @implementation AWCViewController @synthesize webView; - (void)viewDidLoad
--- .h file
{ UIWebView *webView; }
@property (nonatomic, strong) IBOutlet UIWebView *webView;
@end
--- .m file
@implementation AWCViewController
@synthesize webView;
- (void)viewDidLoad {
[super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib.
NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"url/images/image1.png"]];
[self.webView loadRequest:request];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
而不是@“url/images/image1.png”
做
NSString*image=“image1”//您可以将其作为任何名称传递到方法中
[NSString StringWithFormat:(@“url/images/%@.png”,image)] 而不是@“url/images/image1.png”
做
NSString*image=“image1”//您可以将其作为任何名称传递到方法中
[NSString StringWithFormat:(@“url/images/%@.png”,image)] 你有两个选择
NSString
或NSURL
函数更改URL;您将需要类似于ImageOfDayName
的方法来返回每天的NSStringURL/images/imageofday.png
NSString
或NSURL
函数更改URL;您将需要类似于ImageOfDayName
的方法来返回每天的NSStringURL/images/imageofday.png
我建议使用案例2,但两者都可以。有几种方法可以做到这一点,一切都取决于您希望如何管理在线图像
- (NSString *)dailyImageName
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyyMMdd"];
return [dateFormatter stringFromDate:[NSDate date]];
}
因此,您知道您的图像文件名必须是yearmonthday.png(例如“20130413.png”)有几种方法可以做到这一点,一切都取决于您希望如何管理在线图像
- (NSString *)dailyImageName
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyyMMdd"];
return [dateFormatter stringFromDate:[NSDate date]];
}
那么你就知道你的图像文件名必须是yearmonthday.png(例如“20130413.png”)那么,问题是什么?问题是如何让应用程序在图像名称每天变化时更新图像名称。例如今天的图像名称是223,明天是224,接下来是225。那么,问题是什么?问题是如何让应用程序在图像名称每天变化时更新图像名称。例如今天图像名称是223,明天是224,接下来是225。每日图像url每天都会更改。每日图像url每天都会更改。谢谢这是我要找的。谢谢这是我要找的。