-1

I have a tableview and I want you to press a certain cell appears alertview with personalized data for each cell. This is the code:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

NSString *message=[NSString stringWithFormat:@"%@", [tableViewData objectAtIndex:indexPath.row]];


if (message == @"Juan") {

UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Alerta" message:@"Ciudad de México" delegate:self cancelButtonTitle:@"Cerrar" otherButtonTitles:nil];

[alert show];

}

}

You see if I press the cell that says Juan see a UIAlertView and if I press another cell appears Pedro UIAlertView and if for each cell but pressing the cell does not appear in alertview I'm wrong I hope I can help and can not find solution from and through .

Ryan M
  • 18,333
  • 31
  • 67
  • 74
Geovany
  • 1
  • 2
  • still does not work, here the link http://stackoverflow.com/q/11587330/1539443 – Geovany Jul 20 '12 at 22:09
  • Does this answer your question? [String comparison in Objective-C](https://stackoverflow.com/questions/2592511/string-comparison-in-objective-c) – Ryan M May 05 '21 at 01:47

1 Answers1

1

You cannot test strings for equality with ==, so your test message == @"Juan" will always fail. Use [message isEqualToString:@"Juan"] instead.

Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
  • thanks but still I have a doubt because you still can not work as I wish :( here the link http://stackoverflow.com/q/11587330/1539443 – Geovany Jul 20 '12 at 22:23