2011-10-13 7 views
0

필자는 uitableview를 가지고 있지만 일부 셀을 비활성화하고 다른 셀을 활성화하려고합니다.uitableview의 특정 셀 변경

if ([indexPath row] > 0) { 
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    cell.userInteractionEnabled = NO; 
    cell.textLabel.textColor = [UIColor lightGrayColor]; 
} 

하지만 그 대신 모든 셀을 비활성화하고 첫 가능, 그것은 불가능 모든 셀을 마지막 수 : 은 내가 cellForRowAtIndexPath의 첫 번째를 제외한 모든 세포를 해제하려면 다음 코드를 사용했다. 왜 이런 일이 생길까요? 그리고 작동하도록하려면 어떻게해야합니까?

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

    sectionContents = [[self listOfItems] objectAtIndex:[indexPath section]]; 
    contentsForThisRow = [sectionContents objectAtIndex:[indexPath row]]; 

    if ([indexPath row] > 0) { 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
     cell.userInteractionEnabled = NO; 
     cell.textLabel.textColor = [UIColor lightGrayColor]; 
    } 
    static NSString *CellIdentifier = @"Cell"; 

    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    cell.textLabel.text = contentsForThisRow; 
    return cell; 
} 
+2

'cellForRowAtIndexPath : – Nekto

답변

0

당신이 셀을 선언 할 경우 당신은 표시되지 않습니다이 하나

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

    sectionContents = [[self listOfItems] objectAtIndex:[indexPath section]]; 
    contentsForThisRow = [sectionContents objectAtIndex:[indexPath row]]; 

    static NSString *CellIdentifier = @"Cell"; 

    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1  reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    cell.textLabel.text = contentsForThisRow; 
    if ([indexPath row] > 0) { 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
     cell.userInteractionEnabled = NO; 
     cell.textLabel.textColor = [UIColor lightGrayColor]; 
    } 
    return cell; 
} 
+0

'의 모든 코드를 게시하십시오! 나는 어리석은 실수를했다는 것을 믿을 수 없다 ... – Amar

0

cellForRowAtIndexPath:의 코드를 교체,하지만 당신이하고있는 것은 :

은 BTW 여기에 모든 cellForRowAtIndexPath 내 코드입니다 실제 세포를 가져 오기 전에 전에 userinteractionEnabled를 으로 설정하십시오!

메서드의 끝에이 사용자 지정 코드를 입력해야합니다.

또한 메서드에서 셀 변수를 선언하려고 시도했지만 다른 곳에서는 사용하지 않아야합니다.

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

    sectionContents = [[self listOfItems] objectAtIndex:[indexPath section]]; 
    contentsForThisRow = [sectionContents objectAtIndex:[indexPath row]]; 

    static NSString *CellIdentifier = @"Cell"; 

    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    if ([indexPath row] > 0) { 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
     cell.userInteractionEnabled = NO; 
     cell.textLabel.textColor = [UIColor lightGrayColor]; 
    } 

    cell.textLabel.text = contentsForThisRow; 
    return cell; 
} 
+0

내가 처음 =)) – Nekto

+0

대답 시간보기, 내 것은 14 분 전, 15 개월 전 ^^ – Geoffroy

+0

예, 전 일찍이었습니다. – Nekto