开发者

How to call weather forecast condition image in iPhone

I am create on application for weathercondition by nsxmlparser using. I have created three class for parser 1st class name is 'forecastinformation' 2nd class name is 'currentcondition' and 3rd class name is 'forecastecondition'.

I done with all this my all value come in console it work fine in my custom cell I get all currentcondition with forecastcondition in first cell the the value of current condition is printing correct but in my next 3cell depend on forecastinformation class bes in this class I have future information about weather for eg:today is tuesday then he will show information about next day means wednesday,thursday,friday this information will print in my cell I call all value it show proper but I cannot call image with match different weather conditions.

I have to call custom i开发者_高级运维mage with commpare name with condition name. Condition name means I get value from xml in console I write code for this I create if condition but it not work it only show image for currentcondition only it not show me next image on next forecastcondition so how to work on this I create three function for forecast condition for pront image and create 3global value like photo,photo1and photo2 like this but it not get image for me.

Here is my code what i try for print

- (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";
    }

}


Instead of

cell.weatherimage.image = [UIImage imageNamed:photo1];

you can use

cell.weatherimage.image =[UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"http://www.google.com%@",cond1.Icon]];

This will load images from a given url. And instead of doing synchronous loading of images in cell you should use lazy loading approach for better performance.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜