0

I was trying to see if a UITableView cell contains a string.

I have tried using:

if ([cell.textlabel.text rangeOfString:@"Ok"].location !=NSNotFound) 
{
}

But that was no use. It found the text every time no matter what.

Unheilig
  • 16,196
  • 193
  • 68
  • 98

2 Answers2

1

You should test if the cell.textlabel.text string is not nil. I've tested your code with a nil value and always returns TRUE.

if(cell.textlabel.text)
{
    if ([cell.textlabel.text rangeOfString:@"Ok"].location !=NSNotFound) 
    {
        ...
    }

}
LuisEspinoza
  • 8,508
  • 6
  • 35
  • 57
0

Try like this below:-

NSString *str=cell.textlabel.text;
if ([str rangeOfString:@"Ok"].location !=NSNotFound) 
{
}
Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56