NSString在视图控制器中丢失其值

时间:2015-03-13 04:56:16

标签: ios

在我的应用程序中,我将一些字符串从视图控制器传递到另一个视图控制器。

  • 查看控制器A = MainViewController
  • 查看控制器B = NuevoServicioViewController

将NString从A传递到B

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Make sure your segue name in storyboard is the same as this line
    if ([[segue identifier] isEqualToString:@"nuevo_servicio_segue"])
    {
        NSLog(@"estoy en segue pasando a nuevo servicio");
        // Get reference to the destination view controller
        NuevoServicioViewController *vc = [segue destinationViewController];
        //pasamos la latitud del PO
        //la convertimos a String
        NSString *latitud  = [NSString stringWithFormat:@"%.20f", self.puntoOrigen.latitude];
        vc.parametro_origin_latitude = latitud;
        //lo comprobamos
        NSLog(@"LATITUD DEL PO PASADA=%@",latitud);
        //pasamos la lONGITUD del PO
        //la convertimos a String
        NSString *longitud  = [NSString stringWithFormat:@"%.20f", self.puntoOrigen.longitude];
        vc.parametro_origin_longitude = longitud;
        //lo comprobamos
        NSLog(@"LONGITUD DEL PO PASADA=%@",longitud);

    }
}

记录视图以验证字符串是否正确:

2015-03-12 22:37:31.966 ABCTaxi[811:60b] LATITUD DEL PO PASADA=31.71179790294406686257

现在在B中,记录以检查是否收到字符串:

 //3. origin_latitude, la recibimos de mainview

    NSLog(@"LATITUD RECIBIDA DE MAINVIEW=%@",self.parametro_origin_latitude);

记录视图以验证收到的字符串是否相同:

[811:60b] LATITUD RECIBIDA DE MAINVIEW=31.71179790294406686257

在B结束时,按钮操作方法在进一步处理之前,另一个日志验证字符串是否正确:

- (IBAction)boton_tomar_taxi_action:(id)sender {
    //COMPROBAMOS QUE ESTAN TODOS LOS PARAMETROS
    //PARAMETRO 1 CLIENT
    NSLog(@"client = %@", self.parametro_client);
    //PARAMETRO 2 ORIGIN
      NSLog(@"origin = %@", self.parametro_origin);
    //PARAMETRO 3 ORIGIN_LATITUDE
    NSLog(@"origin_latitude = %@", self.parametro_origin_latitude);
    //PARAMETRO 4 ORIGIN_LATITUDE
    NSLog(@"origin_longitude = %@", self.parametro_origin_longitude);
    //PARAMETRO 5. DATE
    NSLog(@"date = %@", self.parametro_date);

}

最后字符串 null

[811:60b] origin_latitude = (null)

我无法找到最后字符串不相同的原因。 请帮我确定一下原因。 谢谢

2 个答案:

答案 0 :(得分:1)

将您的属性更改为strong,这应该可以解决问题。

答案 1 :(得分:1)

将此@property (weak, nonatomic)NSString *parametro_origin_latitude;更改为此@property (strong, nonatomic)NSString *parametro_origin_latitude;