2009-10-30 7 views
0

나는 다음과 같은 목표 - C 함수if 문이 실행되지 않는 이유는 무엇입니까?

- (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 
} 
} 

내가 원하는 건입니다을 가지고있는 행은 내 이름과 동일 할 때 문이 발생하는 경우 - 매우 흥미로운.

if (aName == @"Toby") 

내가 경고에 넣어하고 값이 설정되고 그가 토비로 설정되어 있지만, If 문 그냥 다른 부분을 실행하지 않습니다. 분명히 내가 누락 된 것은 간단합니다.

나는 목표 - C

답변

9

if 문을 배우고 :

if (aName == @"Toby") 

포인터가 아닌 문자열을 비교합니다. 원하는 :

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

이것은 일반 C와별로 다르지 않습니다. 거기에 문자열을 비교하기 위해 ==을 사용할 수 없습니다.

+0

고맙습니다. 그래서 아직까지는 거의 :) –

관련 문제