views:

85

answers:

1

I have the following Objective-c Function

  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{


NSUInteger section = [indexPath section];
NSUInteger row = [indexPath row];

NSString *key = [keys objectAtIndex:section];
NSArray *nameSection = [mysearchdata objectForKey:key];

static NSString *SectionsTableID = @"SectionsTableID";
static NSString *TobyCellID = @"TobyCellID";

NSString *aName = [nameSection objectAtIndex:row]; 

if (aName == @"Toby")
{
 TobyCell *cell = [tableView dequeueReusableCellWithIdentifier:TobyCellID];  
 if (cell == nil)
 {  
  NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"TobyCell" owner:self  options:nil];
  for (id oneObject in nib)
   if ([oneObject isKindOfClass:[TobyCell class]])
    cell = (TobyCell *)oneObject; 
 }          
 cell.lblName.text = [nameSection objectAtIndex:row];
 return cell;  
}
else
{
 //standard cell loading code
}
}

All I want is for the if Statement to fire when the Row is equal to My Name - very exciting.

if (aName == @"Toby")

I have put in an alert and the Value is being set and its being set to Toby but the If statement is not executing just the else part. It is obviously something simple that I'm missing.

I am learning Objective-C

+9  A: 

This if statement:

if (aName == @"Toby")

compares pointers, not strings. You want:

if ([aName isEqualToString:@"Toby"])

This isn't really different from plain C; you can't use == to compare strings there either.

Carl Norum
Thankyou. So near yet so far :)
Toby Allen