解释我的问题有点复杂。我正在使用FGallery库https://github.com/gdavis/FGallery-iPhone,尤其是它的功能,可以从URL地址加载图像。当我对URL路径进行硬编码时,它会超级工作,但是我将字符串变量传递给我创建的类不起作用。我试图调试它,似乎一切正常,有一个字符串分配给变量和一切,但不显示图片。我正在循环中使用ARC。
-(void) loadSoftia
{
//======================================================================================
//THIS WORKS CORRECTLY!!!
wcSofia = [[NSMutableArray alloc] init];
Webcam *s1 = [[Webcam alloc]init];
s1.description=@"Sofia";
s1.location = @"http://www.ampthillweatherstation.info/currentweather/webcamimage.jpg";
[wcSofia addObject:s1];
//======================================================================================
NSMutableString *urlGetOthersLocations =[NSMutableString stringWithFormat:@"http://%@/WebHandlers/%@", @"192.168.188.204", @"BGCam.ashx"];
ServerResponse *serverResponseOthersLocations = [HelperViewController getJsonDataFromTheServer:urlGetOthersLocations];
if(serverResponseOthersLocations.data!=nil)
{
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:serverResponseOthersLocations.data
options:NSJSONReadingMutableLeaves|NSJSONReadingMutableContainers
error:nil];
[wcSofia removeAllObjects];
Webcam *wc;
int i=0;
for (NSDictionary *locationsDic in dic){
NSString *key;
for ( key in locationsDic) {
NSLog(@"%@ = %@", key, [locationsDic objectForKey: key]);
}
NSLog(@"%@", [locationsDic objectForKey:@"URL"]);
NSLog(@"%@ = %@", locationsDic, [locationsDic objectForKey: locationsDic]);
NSString *url =[locationsDic objectForKey:@"URL"];
// NSLog(@"%@", url);
NSMutableString* theString = [NSString stringWithFormat:@"%i ",i];
wc = [[Webcam alloc]initWithLocation: [NSString stringWithFormat:@"%@", url] withDescription:@"description"];
wc.location = url;//DOESNT WORK!
wc.description =@"София";// theString;//[NSString stringWithFormat:@"%@", @"aa"]; // @"София";
wc.location = @"http://media.borovets-bg.com/cams/channel?channel=61";//IT WORKS BECAUSE IT IS HARDCODED
if(wcSofia!=nil)
{
[wcSofia addObject:wc];
NSLog(@"%@", wc.location);
}
i++;
}
}
}
我评论了一段有效的代码,但没有。 我想你不需要整个程序,因为它向我的本地Web服务器发出请求以获取URL地址和描述,但相信我这件事情很完美。 感谢您帮助解决这个谜团。 编辑: 完整的源代码:https://dl.dropboxusercontent.com/u/46512232/FGallery.zip