2012-04-29 11 views
13

Estoy tratando de cambiar el comportamiento de las células a: 1) Cuando la célula roscado, Mark celular como completa con una marca de verificación 2) Cuando se pulsa el botón de accesorios Divulgación Detalle, realiza el Segue. 3) En tableView: didSelectRowAtIndexPath: Tengo:en iOS, ¿Por qué ocurre antes de prepareForSegue didSelectRowAtIndexPath

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
    AWDelivery *delivery = [self.fetchedResultsController objectAtIndexPath:indexPath]; 
    [delivery toggleDelivered: delivery]; 
    [self configureCheckmarkForCell:cell withDelivery:delivery]; 
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
    if (debugging) NSLog(@"[%s] [%d]", __PRETTY_FUNCTION__, __LINE__); 
} 

la deselectRowAtIndexPath se supone que debe pasar por alto la segue, pero no lo es.

NSLogs: a) el 2012-04-29 18: 50: 00,848 de entrega [3148: FB03] [- [DeliveryTVC prepareForSegue: remitente:]] [168] b) el 2012-04-29 18: 50: 01.245 Entrega [3148: fb03] [- [Tabla de DeliveryTVCView: didSelectRowAtIndexPath:]] [93]

tenga en cuenta que 'didSelect' aparece después de 'prepareForSegue'.

Cualquier sugerencia sería muy apreciada.

+0

Puede por favor compartir su código. Tengo el mismo problema. Gracias. – applefreak

+0

Muy aleatorio, pero a partir de su ejemplo de código, aprendí sobre las macros '__PRETTY_FUNCTION__' y' __LINE__'. ¡Gracias! – Guven

Respuesta

14

¿Tiene su segue de detalles conectado a la celda de la vista de tabla? En su lugar, intente arrastrarlo entre los dos controladores de vista (el que contiene la tabla y el que desea que vaya).

A continuación, realice manualmente ([self performSegueWithIdentifier:@"MySegue"];) cuando tableView:accessoryButtonTappedForRowWithIndexPath:.

+1

¡¡Justo en el dinero !!!!!!! Ese pequeño factoid debería ser más pronunciado. – JJW

+0

¿Puede agregar algún código para realizar segue manualmente, por favor? Tengo un problema similar en el que quiero pasar la información de la celda al siguiente controlador de vista. ¿Quiso decir realizar presentación manual viewcontroller manualmente o prepareforsegue método? Gracias. – applefreak

+1

Claro, siempre que necesite ver el controlador, diga: [self performSegueWithIdentifier: @ "MySegue"]; esa cadena debe coincidir con el identificador que configuró para el segue en IB. Avíseme si necesita detalles adicionales. – danh

6

Si necesita obtener la selección de tabla actual en prepareForSegue, puede obtenerla accediendo a tableView ivar de UITableViewController;

[self tableView] indexPathForSelectedRow] 
+0

Al tocar el botón de accesorio no se selecciona la celda, por lo que indexpath.row no se corresponde con la celda correcta para el accesorio girado. – swampf0etus

1
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    // Make sure your segue name in storyboard is the same as this line 
    if ([[segue identifier] isEqualToString:@"ClaimDetailsSeque"]) 
    { 
     DLog(@"destinationViewController %@",[[segue destinationViewController] topViewController]); 
     //This syntax is needed when the seque is going through a Navagation Controller 
     ClaimDetailsFormViewController* vc = (ClaimDetailsFormViewController*)[[segue destinationViewController] topViewController]; 

     //This the the way to get the object from the selected row via the FetchedResultsController 
     //this is needed because prepareForSegue is called before didSelectRowAtIndexPath 
     NSIndexPath *selectedIndexPath = [self->claimTableView indexPathForSelectedRow]; 
     ClaimHistory *object = [[self claimHistoryFetchedResultsController] objectAtIndexPath:selectedIndexPath]; 

     MyClaimHistorySM *myCH = [MyClaimHistorySM new]; 

     myCH.policyNumber = object.policyNumber; 
     myCH.policyStatus = object.policyStatus; 
     myCH.claimNumber = object.claimNumber; 
     myCH.insuredName = object.insuredName; 
     myCH.lossDescription = object.lossDescription; 
     myCH.dateOfLoss = object.dateOfLoss; 
     myCH.incidentCloseDt = object.incidentCloseDt; 

     vc.claimHistorySM = myCH; 

    } 

} 

Seque on Storyboard

+0

La transición se creó en IB seleccionando la celda de vista de tabla y arrastrando el "conector" de selección de Segmentos activados al controlador de navegación. –

Cuestiones relacionadas