2014-04-01 2 views
0

이 코드를 사용하며 호출을 반환 할 수 없습니다 (if 문에 오류가 있기 때문에 오류가 발생했습니다). 나는이 진술이 필요하다. 어떻게 해결할 수 있습니까?if 문에서 UITableViewCell

static NSString *cellIdentifierCell = @"Cell"; 
static NSString *cellIdentifierCol = @"Col"; 
WallPost *wallPost = self.dataSource[indexPath.row]; 


if ([wallPost.images count] >= 2) 
{ 
    AFTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifierCol]; 
    if (cell == nil) 
    { 
     cell = [[AFTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifierCol]; 
    } 
} 

     if ([wallPost.images count] < 2) 
{ 
    FeedCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifierCell]; 
    if (cell == nil) 
    { 
     cell = [[FeedCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifierCell]; 

    //some code 
    } 
    cell.cellTextLabel.text = wallPost.text; 
    cell.cellTextLabel.numberOfLines = 0; 

    cell.cellLikeLabel.text = [NSString stringWithFormat:@"%@", wallPost.likesCount]; 
    cell.cellCommentsLabel.text = [NSString stringWithFormat:@"%@", wallPost.commentsCount]; 
    cell.cellDateLabel.text = [NSString stringWithFormat:@"%@", wallPost.pubDate]; 

} 
+0

밖에서 선언 –

+0

@MidhunMP MP, 어떻게 그들이 할 수있는 동일한 이름과 다른 유형 이자형? – user3486428

+0

'{}'안에 변수를 선언하면 대괄호 바깥 쪽에서 변수를 볼 수 없습니다. 'if' 문 앞에 변수를 선언하고 그것들을 nil로 설정하십시오. ** 이것은 Objective-C를 사용하기 전에 알아 두어야 할 매우 기본적인 C 언어입니다. ** –

답변

0

당신이 상호 배타적이 if의 두 지점에 두 개의 셀을 선언하고 있기 때문에, 당신은 모두 return 문을 배치 할 수 있습니다, 해당 cell 변수는 범위에 여기서

if ([wallPost.images count] >= 2) { 
    AFTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifierCol]; 
    if (cell == nil) { 
     cell = [[AFTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifierCol]; 
    } 
    return cell; 
} else { // [wallPost.images count] < 2 
    FeedCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifierCell]; 
    if (cell == nil) { 
     cell = [[FeedCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifierCell]; 
     //some code 
    } 
    cell.cellTextLabel.text = wallPost.text; 
    cell.cellTextLabel.numberOfLines = 0; 

    cell.cellLikeLabel.text = [NSString stringWithFormat:@"%@", wallPost.likesCount]; 
    cell.cellCommentsLabel.text = [NSString stringWithFormat:@"%@", wallPost.commentsCount]; 
    cell.cellDateLabel.text = [NSString stringWithFormat:@"%@", wallPost.pubDate]; 
    return cell; 
} 
+1

감사합니다. – user3486428

0

당신은 해결할 수 그것 외부에 선언하여 :

static NSString *cellIdentifierCell = @"Cell"; 
static NSString *cellIdentifierCol = @"Col"; 
WallPost *wallPost = self.dataSource[indexPath.row]; 

// Base class pointer 
UITableViewCell *returnCell = nil; 

if ([wallPost.images count] >= 2) 
{ 
    AFTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifierCol]; 
    if (cell == nil) 
    { 
     cell = [[AFTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifierCol]; 
     returnCell = cell; 
    } 
} 

if ([wallPost.images count] < 2) 
{ 
    FeedCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifierCell]; 
    if (cell == nil) 
    { 
     cell = [[FeedCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifierCell]; 
    } 
    cell.cellTextLabel.text = wallPost.text; 
    cell.cellTextLabel.numberOfLines = 0; 

    cell.cellLikeLabel.text = [NSString stringWithFormat:@"%@", wallPost.likesCount]; 
    cell.cellCommentsLabel.text = [NSString stringWithFormat:@"%@", wallPost.commentsCount]; 
    cell.cellDateLabel.text = [NSString stringWithFormat:@"%@", wallPost.pubDate]; 
    returnCell = cell; 

} 

return returnCell;