Search code examples
iphoneobjective-cxcode4

UITableView with UIAlertView


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 .


Solution

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