Неправильная прокрутка UITableview - PullRequest
0 голосов
/ 02 декабря 2011

Мой 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;}

на самом деле я разбираю новости о погоде с сайта Можете ли вы сказать мне, как я могу решить DIS

1 Ответ

0 голосов
/ 02 декабря 2011

прочитайте следующую ссылку, это может помочь u

http://www.e -string.com / content / custom-uitableviewcells-interface-builder http://blog.webscale.co.in/?p=284 http://www.icodeblog.com/2009/05/24/custom-uitableviewcell-using-interface-builder/

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...