Отладка с iPhone 3G; он пропускает cellForRowAtIndexPath

У меня странная проблема. У меня есть код, который отлично работает на iPhone Simulator Xcode 3, но когда я отлаживаю с iPhone 3G, он пропускает часть кода.

у меня есть UITableView он берет свои данные из CSV на сервере (он может прочитать файл, который я тестировал с помощью журнала), но таблица не заполняется. Итак, я обнаружил, что он полностью пропускает cellForRowAtIndexPath: метод.

Вот код:

    - (void)viewDidLoad {
    [super viewDidLoad];

    //Inizializzo la posizione di partenza e calcolo distanza
    CLLocation *startPos = [[CLLocation alloc]initWithLatitude:ST_LAT longitude:ST_LONG];
    CLLocationDistance distanza = [posizione distanceFromLocation:startPos];

    NSLog(@"Latitudine: %f",posizione.coordinate.latitude);
    NSLog(@"Longitudine: %f",posizione.coordinate.longitude);
    NSLog(@"Distanza (in metri): %f",distanza);

    //Creo una lista temporaneamente non ordinata
    NSMutableArray *listaNonOrdinata = [[NSMutableArray alloc]init];

    //Prelevo dati da CSV e li inserisco in record
//  NSString *fileString = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Lista1" ofType:@"csv"] encoding:NSUTF8StringEncoding error:nil];
    NSString *fileString = [NSString stringWithContentsOfURL:[NSURL URLWithString:URL_CSV] encoding:NSUTF8StringEncoding error:nil];
    NSLog(@"fileString: %@", fileString);
    record = [fileString csvRows];

    //Inserisco titolo
    self.navigationItem.title = [[record objectAtIndex:0]objectAtIndex:C_TIPOLOGIA];

    //Creo oggetto doppio per verificare se è presente più di una volta
    id doppio = nil;

    //Controllo tutto il record e inserisco nella listaNonOrdinata solo i dati singoli
    //se il dato è doppio inserisco il rispettivo BOOL
    for (int i=1; i < record.count; i++) {
        //Carico un array temporaneo con tutti gli oggetti con chiave Item
        NSMutableArray *temp = [[NSMutableArray alloc]init];
        for (int j=0; j < listaNonOrdinata.count; j++) {
            [temp addObject:[[listaNonOrdinata objectAtIndex:j]objectForKey:@"Item"]];
        }
        //Controllo che nessuno di questi sia già presente
        doppio = [[record objectAtIndex:i] firstObjectCommonWithArray:temp];
        [temp release];

        //Inizializzo posizione oggetto
        NSNumberFormatter *form = [[NSNumberFormatter alloc]init];
        NSNumber *lat = [form numberFromString:[[record objectAtIndex:i]objectAtIndex:C_LAT]];
        NSNumber *longit = [form numberFromString:[[record objectAtIndex:i]objectAtIndex:C_LONG]];
        [form release];
        CLLocation *posObj = [[CLLocation alloc]initWithLatitude:(CLLocationDegrees)[lat floatValue] 
                                                       longitude:(CLLocationDegrees)[longit floatValue]];

        //Se mi trovo nel raggio
        if (distanza < RAGGIO) {
            //Controllo che l'oggetto si trovi entro il raggio
            if ([posObj distanceFromLocation:startPos] < RAGGIO) {
                //Se non è doppio lo inserisco con Bool NO
                if (doppio == nil) {
                    NSMutableDictionary *dizionario = [[NSMutableDictionary alloc]init];
                    [dizionario setObject:[[record objectAtIndex:i]objectAtIndex:C_TIPOLOGIA] forKey:@"Item"];
                    [dizionario setObject:[NSNumber numberWithBool:NO] forKey:@"Bool"];
                    [listaNonOrdinata addObject:dizionario];
                    [dizionario release];
                } else {
                    //Cerco l'elemento doppio e gli sostituisco il Bool a YES
                    for (int j=0; j < listaNonOrdinata.count; j++) {
                        if ([[[listaNonOrdinata objectAtIndex:j]objectForKey:@"Item"] isEqualToString:[[record objectAtIndex:i]objectAtIndex:C_TIPOLOGIA]]) {
                            NSMutableDictionary *dizionario = [[NSMutableDictionary alloc]init];
                            [dizionario setObject:[[record objectAtIndex:i]objectAtIndex:C_TIPOLOGIA] forKey:@"Item"];
                            [dizionario setObject:[NSNumber numberWithBool:YES] forKey:@"Bool"];
                            [listaNonOrdinata replaceObjectAtIndex:j withObject:dizionario];
                            [dizionario release];
                            break;
                        }
                    }
                }
            }
        } else {
            //Controllo che l'oggetto si trovi fuori dal raggio
            if ([posObj distanceFromLocation:startPos] > RAGGIO) {
                //Se non è doppio lo inserisco con Bool NO
                if (doppio == nil) {
                    NSMutableDictionary *dizionario = [[NSMutableDictionary alloc]init];
                    [dizionario setObject:[[record objectAtIndex:i]objectAtIndex:C_TIPOLOGIA] forKey:@"Item"];
                    [dizionario setObject:[NSNumber numberWithBool:NO] forKey:@"Bool"];
                    [listaNonOrdinata addObject:dizionario];
                    [dizionario release];
                } else {
                    //Cerco l'elemento doppio e gli sostituisco il Bool a YES
                    for (int j=0; j < listaNonOrdinata.count; j++) {
                        if ([[[listaNonOrdinata objectAtIndex:j]objectForKey:@"Item"] isEqualToString:[[record objectAtIndex:i]objectAtIndex:C_TIPOLOGIA]]) {
                            NSMutableDictionary *dizionario = [[NSMutableDictionary alloc]init];
                            [dizionario setObject:[[record objectAtIndex:i]objectAtIndex:C_TIPOLOGIA] forKey:@"Item"];
                            [dizionario setObject:[NSNumber numberWithBool:YES] forKey:@"Bool"];
                            [listaNonOrdinata replaceObjectAtIndex:j withObject:dizionario];
                            [dizionario release];
                            break;
                        }
                    }
                }
            }
        }
    }

    //Ordino listaNonOrdinata in ordine alfabetico
    lista = [[NSArray alloc]init];
    NSComparator comparatore = ^NSComparisonResult(id aDictionary, id anotherDictionary) {
        return [[aDictionary objectForKey:@"Item"] localizedCaseInsensitiveCompare:[anotherDictionary objectForKey:@"Item"]];
    };
    lista = [listaNonOrdinata sortedArrayUsingComparator:comparatore];
    [listaNonOrdinata release];
    [startPos release];

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;

    //Retain:
    [lista retain];
    [record retain];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return lista.count;
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    // Configure the cell...
    NSString *cellValue = [[lista objectAtIndex:indexPath.row]objectForKey:@"Item"];
    cell.textLabel.text = cellValue;

    NSLog(@"dettaglio bool Value: %@",[[[lista objectAtIndex:indexPath.row]objectForKey:@"Bool"]boolValue] ? @"YES" : @"NO");

    if ([[[lista objectAtIndex:indexPath.row]objectForKey:@"Bool"]boolValue]) {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }

    [cellValue release];

    return cell;
}

Код немного сложен для других функций, но это необходимо для понимания проблемы.

РЕДАКТИРОВАТЬ: Я решил проблему.. Он не выполнил этот кусок кода, потому что lista.count остался 0 и не был заполнен из-за неправильного формата строки в число из CSV. Я просто изменил "." с "," в каждом выпуске, а потом все заработало... Не понимаю, почему симулятор работал с устройством нет, может ПК без проблем принимает запятые и точки

1 ответ

Если твой cellForRowAtIndexPath: не вызывается, вы должны проверить, если datasource Делегат связан с таблицей (либо в Интерфейсном Разработчике, либо назначен в коде).

Другие вопросы по тегам