Pregunta

Tengo 2 clases para UITableViewCell que muestran datos diferentes pero usan la misma tabla.

Estoy intentando completar la tabla en 2 pasos usando una var bool, pero parece que obtengo una excepción porque la celda obtiene la asignación de primera clase y no puede mutar...

Básicamente tengo que ir al celular a clases extendidas.

@interface PatientsCellNewPager : UITableViewCell { } 
@interface DoctorsCellNewPager : UITableViewCell { } 

el código se frena cuando estoy en el paso 2 e intento cambiar el tipo de celda y da una excepción en [cell setData:set cellid:[NSString stringWithFormat:@"%d",indexPath.row] ];en la fase==2 si bloque..

esto se debe a que la celda según el depurador todavía tiene el tipo DoctorsCellNewPager desde la primera inicialización....

¿Cómo puedo hacerlo de otra manera?Tiene que estar en la misma página usando la misma instancia de la clase pero usando múltiples diseños y definiendo el diseño de la celda en el lugar... sería una opción terrible.

aquí está mi código

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

    static NSString *CellIdentifier = @"Cell";



    if (phase==2) { //patient


        PatientsCellNewPager *cell =(PatientsCellNewPager *)  [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[PatientsCellNewPager alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }







        PatientsSet *set = (PatientsSet *)[patients_set objectAtIndex:indexPath.row];       

        NSLog(@"logg %d",indexPath.row);    


        [cell setData:set cellid:[NSString stringWithFormat:@"%d",indexPath.row] ]; 




           return cell;

    }
    else if (phase==1) { //doctor


        DoctorsCellNewPager *cell =(DoctorsCellNewPager *)  [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[DoctorsCellNewPager alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
        }





            // Set up the cell

            DoctorsSet *set = (DoctorsSet *)[doctors_set objectAtIndex:indexPath.row];      


              [cell setData:set cellid:[NSString stringWithFormat:@"%d",indexPath.row] pass:YES ];  





        return cell;


    }


    return nil;

}

aquí está mi error

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DoctorsCellNewPager setData:cellid:]: unrecognized selector sent to instance 0x181690'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x323ef64f __exceptionPreprocess + 114
    1   libobjc.A.dylib                     0x36632c5d objc_exception_throw + 24
    2   CoreFoundation                      0x323f31bf -[NSObject(NSObject) doesNotRecognizeSelector:] + 102
    3   CoreFoundation                      0x323f2649 ___forwarding___ + 508
¿Fue útil?

Solución

Eso es un problema muy común y muchas personas se encontraron con eso, recientemente tuve que lidiar con ese problema.

Matt Gallagher publicó un gran tutorial sobre cómo lograrlo en su blog:

células heterogéneas en un UTIUTVIEWCONCROLERER


Bueno, acabo de tener una idea sobre cómo podría funcionar ..
// Esto es altamente experimental y no se ha probado :

static NSString *PatientsCellIdentifier = @"PatientsCellNewPager";
static NSString *DoctorsCellIdentifier = @"DoctorsCellNewPager";

UITableViewCell *cell;
if(patient) {
    cell = [tableView dequeueReusableCellWithIdentifier:PatientsCellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] 
        initWithStyle:UITableViewCellStyleDefault 
        reuseIdentifier:PatientsCellIdentifier] autorelease];
    }
    // Setup cell for patient -> maybe you could use -configureCell:atIndexPath:
} else if (doctor) {
    cell = [tableView dequeueReusableCellWithIdentifier:DoctorsCellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] 
        initWithStyle:UITableViewCellStyleDefault 
        reuseIdentifier:DoctorsCellIdentifier] autorelease];
    }
    // Setup cell for doctor -> maybe you could use -configureCell:atIndexPath:
}

return cell;

Déjame saber si esto te trajo más ...

hth

Otros consejos

Te has perdido el pass:.. parámetro al final y el método que estás llamando, [DoctorsCellNewPager setData:celled:], no tiene el parámetro pass colocar.Así que agrega el pass parámetro y debería funcionar bien.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top