UITableview的滚动不正确

时间:2011-12-02 09:08:37

标签: ios ios4 uitableview

我的UITableView滚动不正确我使用customcell作为

rowAtIndexPath的单元格如下:

(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {  
    static NSString *CellIdentifier = @"Cell";  
    CustomCellWeather *cell = (CustomCellWeather *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];    
    if(cell == nil) {       
        NSArray *topLevelObjects=[[NSBundle mainBundle] loadNibNamed:@"CustomCellWeather" owner:nil options:nil];       
        for(id currentObject in topLevelObjects)        {
            if([currentObject isKindOfClass:[UITableViewCell class]])
            {
                cell = (CustomCellWeather *)currentObject;
            //  cell = [[[CustomCellWeather alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
                break;
            }
        }
    }   
    int index = indexPath.row;
    cell.dayDateLabel.textColor = [UIColor colorWithRed:126/255.0 green:212/255.0 blue:252/255.0 alpha:1];  
    if(index == 0) {        
        cell.contentView.backgroundColor = [UIColor colorWithRed:0 green:102/255.0 blue:179/255.0 alpha:0.5];       
        cell.otherCondition.text = @"";
        cell.dayTempMin_HumidityLabel.text = @"";
        cell.dayConditionLabel.text = @"";
        cell.otherWind.text = @"";
        cell.dayWindLabel.text = @"";       
        cell.dayDateLabel.text = @"Current";
        cell.dayTempMaxLabel.text = [[[resCurrTempC stringByAppendingString:@"°C/"] stringByAppendingString:resCurrTempF] stringByAppendingString:@"°F"];
        cell.todayCondition.text = resCurrWeatherDesc;  
        cell.currentWind.text = [[[currWindDir stringByAppendingString:@" at "] stringByAppendingString:currWindSpeed] stringByAppendingString:@"mph"];
        cell.currentHumidity.text = [resHumidity stringByAppendingString:@"%"];
        NSURL *url = [NSURL URLWithString:currIcon];        
        cell.dayImage.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
    }else {
        cell.hiddenLabel.text = @"";        //represents todayCondition
        cell.todayWind.text = @"";
        cell.currentWind.text = @"";
        cell.todayHumidity.text = @"";
        cell.currentHumidity.text = @"";        
        if(index == 1) {
            cell.contentView.backgroundColor = [UIColor colorWithRed:124/255.0 green:123/255.0 blue:123/255.0 alpha:0.5];
            cell.dayDateLabel.text = @"Today";
        }else{
            //NSDate *today = [NSDate date];

            NSString *dateString = [responseDate objectAtIndex:index-1];
            NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
            // this is imporant - we set our input date format to match our input string
            // if format doesn't match you'll get nil from your string, so be careful
            [dateFormatter setDateFormat:@"yyyy-MM-dd"];
            dateFromString = [[NSDate alloc] init];
            // voila!
            dateFromString = [dateFormatter dateFromString:dateString];
            [dateFormatter release];            
            NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
            [formatter setDateFormat:@"EEEE, MMM dd"];
            NSCalendar *calender = [NSCalendar currentCalendar];        
            NSDateComponents *components = [calender components:( NSHourCalendarUnit ) fromDate:dateFromString];
            //[components setHour:24*(index-1)];
            dateFromString = [calender dateByAddingComponents:components toDate:dateFromString options:0];          
            NSString *stri = [formatter stringFromDate:dateFromString];
            cell.contentView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
            cell.dayDateLabel.text = stri;          
            //[dateFromString release];
            [formatter release];
        }
        cell.dayTempMaxLabel.text = [[[[@"Max:  " stringByAppendingString:[responseTempMaxC objectAtIndex:index-1]] stringByAppendingString:@"°C/"] stringByAppendingString:[responseTempMaxF objectAtIndex:index-1]] stringByAppendingString:@"°F"] ; 
        cell.dayTempMin_HumidityLabel.text = [[[[@"Min:  " stringByAppendingString:[responseTempMinC objectAtIndex:index-1]] stringByAppendingString:@"°C/"] stringByAppendingString:[responseTempMinF objectAtIndex:index-1]] stringByAppendingString:@"°F"] ; 
        cell.dayConditionLabel.text = [responseWeatherDesc objectAtIndex:index-1];      
        cell.dayWindLabel.text = [[[[responseWindDirection objectAtIndex:index-1]stringByAppendingString:@" at "]stringByAppendingString:[responseWindspeedMiles objectAtIndex:index-1]] stringByAppendingString:@"mph"];       
        NSURL *url = [NSURL URLWithString:[responseWeatherIconUrl objectAtIndex:index-1]];
        cell.dayImage.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;}

实际上我正在从网站解析天气新闻 你能告诉我怎样才能解决问题

1 个答案:

答案 0 :(得分:0)