如何在iPhone中调用天气预报条件图像
我是使用nsxmlparser在weathercondition应用程序上创建的。我已经为解析器创建了三个类,第一个类名是“ForecastFormation”,第二个类名是“currentcondition”,第三个类名是“ForecastCondition” 我完成了所有这些我的所有值都在控制台中它在我的自定义单元格中工作正常我在第一个单元格中获得所有当前条件和forecastcondition当前条件的值打印正确,但在我的下一个单元格中取决于forecastinformation类bes在这个类中我有关于天气的未来信息例如:今天是星期二,然后他将显示关于第二天的信息意味着星期三、星期四、星期五。此信息将打印在我的手机中。我称其显示的所有值为正确值,但我无法根据不同的天气条件调用图像 我必须用commpare名称和条件名称调用自定义图像。条件名称意味着我在控制台中从xml中获取值我为此编写代码我创建了if条件但它不起作用它只显示当前条件的图像它不显示下一个预测条件的下一个图像因此如何处理这个问题我为pront图像的预测条件创建了三个函数并创建了3个全局值,如photo,照片1和照片2是这样的,但我看不到 这是我试图打印的代码如何在iPhone中调用天气预报条件图像,iphone,objective-c,Iphone,Objective C,我是使用nsxmlparser在weathercondition应用程序上创建的。我已经为解析器创建了三个类,第一个类名是“ForecastFormation”,第二个类名是“currentcondition”,第三个类名是“ForecastCondition” 我完成了所有这些我的所有值都在控制台中它在我的自定义单元格中工作正常我在第一个单元格中获得所有当前条件和forecastcondition当前条件的值打印正确,但在我的下一个单元格中取决于forecastinformation类bes在
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
TWeatherCell *cell =(TWeatherCell *) [MyTableView dequeueReusableCellWithIdentifier:[NSString stringWithFormat:@"cell_%d", indexPath.row]];
if (cell == nil) {
//cell = [[[TWeatherCell alloc] initWithStyle:UITableViewStyleGrouped reuseIdentifier:CellIdentifier] autorelease];
cell = [[[TWeatherCell alloc] initWithFrame:CGRectZero reuseIdentifier:[NSString stringWithFormat:@"cell_%d", indexPath.row]] autorelease];
}
//this all value cond1,2,3 is my array value i am taking value from array and store in yhis allobject cond1,cond2,cond3
//ForecastCondition *cond=[forecastcond objectAtIndex:0];
cond1=[forecastcond objectAtIndex:1];
cond2=[forecastcond objectAtIndex:2];
cond3=[forecastcond objectAtIndex:3];
switch (indexPath.row) {
case 0:
NSLog(@"%d",indexPath.row);
NSData *imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:currentcond.Icon]];
NSLog(@"this is image from server:%@",imageData);
cell.weatherimage.image = [UIImage imageNamed:photo];
[imageData release];
file://localhost/Users/pradeepyadav/Desktop/JourneyMapper/Journey/Classes/TJourneyTabBar.hcell.weatherimage.image = [UIImage imageNamed:photo];
cell.reportdate.text = _forecastInfo.CurrentDateTime;
cell.conditionname.text = currentcond.Condition;
cell.twotemp.text = [NSString stringWithFormat:@"Temp:%@/%@",currentcond.Tempf,currentcond.Tempf];
cell.twodirection.text = currentcond.WindCondition;
cell.humidity.text = currentcond.Humidity;
break;
case 1:
NSLog(@"%d",indexPath.row);
cell.weatherimage.image = [UIImage imageNamed:photo];
cell.reportdate.text =[NSString stringWithFormat:@"%@",thursday];
cell.conditionname.text = cond1.Condition;
cell.twotemp.text = [NSString stringWithFormat:@"Temp:%@/%@",cond1.Low,cond1.High];
break;
case 2:
NSLog(@"%d",indexPath.row);
cell.weatherimage.image = [UIImage imageNamed:photo1];
cell.reportdate.text = [NSString stringWithFormat:@"%@",friday];
cell.conditionname.text = cond2.Condition;
cell.twotemp.text = [NSString stringWithFormat:@"Temp:%@/%@",cond2.Low,cond2.High];
break;
case 3:
NSLog(@"%d",indexPath.row);
cell.weatherimage.image = [UIImage imageNamed:photo2];
cell.reportdate.text = [NSString stringWithFormat:@"%@",sunday];
cell.conditionname.text = cond3.Condition;
cell.twotemp.text = [NSString stringWithFormat:@"Temp:%@/%@",cond3.Low,cond3.High];
break;
default:
NSLog(@"Out of Range ",indexPath.row);
break;
}
return cell;
}
-(void)selected
{
if ([currentcond.Condition isEqualToString:@"Thunderstorm"])
{
photo=@"google_weather_thunderstorm.png";
}
else if ([currentcond.Condition isEqualToString:@"Mostly Sunny"]) {
photo=@"google_weather_mostly_sunny.png";
}
else if ([currentcond.Condition isEqualToString:@"Mostly Cloudy"]) {
photo=@"google_weather_cloudy.png";
}
else if ([currentcond.Condition isEqualToString:@"Chance of Storm"]) {
photo=@"google_weather_chance_of_storm.png";
}
else if ([currentcond.Condition isEqualToString:@"Clear"]) {
photo=@"google_weather_sunny.png";
}
}
-(void)selected1
{
if ([cond1.Condition isEqualToString:@"Thunderstorm"])
{
photo1=@"google_weather_thunderstorm.png";
}
else if ([cond1.Condition isEqualToString:@"Mostly Sunny"]) {
photo1=@"google_weather_mostly_sunny.png";
}
else if ([cond1.Condition isEqualToString:@"Mostly Cloudy"]) {
photo1=@"google_weather_cloudy.png";
}
}
-(void)selected2
{
if ([cond2.Condition isEqualToString:@"Thunderstorm"])
{
photo2=@"google_weather_thunderstorm.png";
}
else if ([cond2.Condition isEqualToString:@"Mostly Sunny"]) {
photo2=@"google_weather_mostly_sunny.png";
}
else if ([cond2.Condition isEqualToString:@"Mostly Cloudy"]) {
photo2=@"google_weather_cloudy.png";
}
}
而不是
cell.weatherimage.image = [UIImage imageNamed:photo1];
你可以用
cell.weatherimage.image =[UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"http://www.google.com%@",cond1.Icon]];
这将从给定的url加载图像。您应该使用延迟加载方法来获得更好的性能,而不是对单元格中的图像执行同步加载