2

我正在尝试将一些字符串传递给 NSString var,但我在字符串末尾收到垃圾。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    mySegue = cell.textLabel.text;
    NSLog(@"%@",mySegue);
    if ([[self category] isEqualToString:@"restaurantes"]) 
        [self performSegueWithIdentifier:@"restaurante" sender:self];
    else if ([[self category] isEqualToString:@"bares"]){
        [self performSegueWithIdentifier:@"bar" sender:self];
    }
    else if ([[self category] isEqualToString:@"cafes"]){
        [self performSegueWithIdentifier:@"cafe" sender:self];
    }
}

NSSlog 输出正确的字符串,但调试区域在字符串末尾显示垃圾。如下图所示。查看 mySegue var 和 nslog 的输出。 调试 http://i63.photobucket.com/albums/h134/automud/ScreenShot2013-01-21at35430PM.png

cell.textlabel.text 是这样设置的

cell.textLabel.text = [restauranteArray objectAtIndex:row];

restauranteArray 是这样设置的

        NSBundle *bundle = [NSBundle mainBundle];
        NSString *plistPath = [bundle pathForResource:@"RestaurantesList" ofType:@"plist"];
        NSDictionary *dictionary = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
        self.restaurante = dictionary;
        self.restauranteArray = [self.restaurante allKeys];

女巫来自这个plist

plist http://i63.photobucket.com/albums/h134/automud/ScreenShot2013-01-21at42638PM.png

那么,为什么我会在字符串的末尾得到这个垃圾?

编辑--------------我使用 var 传递给下一个视图控制器

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if([segue.identifier isEqualToString:@"restaurante"]){

        PCDetailViewController *detailController = (PCDetailViewController *)segue.destinationViewController;
        detailController.estabelecimento = mySegue;
        detailController.tipo = @"Restaurante";
    }
}

在 viewDidLoad 的下一个视图控制器上,我有这个

    self.estabelecimentoArray = [self.estabelecimentoDic objectForKey:estabelecimento];

当我尝试 objectForKey:estabelecimento 我什么也没得到,因为字符串不匹配

编辑 - - - - - - -

在这里你可以看到输出是 Capitão Grill,但 var 是 Capitão Grill Grill 垃圾 http://i63.photobucket.com/albums/h134/automud/ScreenShot2013-01-21at50213PM.png

4

0 回答 0