2014-12-28 6 views
-1

mothod cellForRowAtIndexPath에서 tableView 맨 위에 표시하려면 tableView 셀을 prfioritize하는 방법? havePriority의 값이 havePrioritybool 값에 따라 우선 순위가 있는지 여부를 확인하는 tableView 셀의 맨 위에 우선 순위 셀을 표시하려면 havePriority이 1 일 경우 true이어야합니다. 그렇지 않으면 우선 순위 목록 뒤에 있어야합니다. . 다른 셀 식별자를 사용하여 시도했지만 상단에서 목록을 가져올 수 없습니다.우선 테이블보기 셀 IOS

내 코드 :

static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 
if (havePriority) // if the cell wants priority to be at top, have a value in bool 
    { 
     cell.textLabel = sOmeText; // 
     NSLog(@"%@",sOmeText); 
    } 
    return cell; 
+0

데이터 원본의 우선 순위를 지정한 다음 reloadData를 다시 지정하십시오. –

답변

0

당신은 그 방법에있는 세포의 순서를 설정 할 수 없습니다. 그때까지는 너무 늦었습니다.

이것은 실제로 모델 계층에서 수행해야하는 작업입니다. 표시 할 항목 목록은 우선 순위에 따라 이미 정렬되어 있어야하며, 이렇게하면 항목이 맨 위에 표시됩니다.

둘째로,이 코드 유형은 더 이상 정말 필요가 없습니다 :

UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 
당신은 더 현대적인 방법을 사용한다

: 이것은 재사용 풀에서 셀을 반환하거나

UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier 
                   forIndexPath:indexPath]; 

을 새 셀을 만들면 항상 셀을 반환하므로 직접 만들 필요가 없습니다.

+0

이 오류가 발생했습니다 : 식별자 Cell을 사용하여 셀을 dequeue 할 수 없음 - 식별자에 대해 nib 또는 클래스를 등록하거나 스토리 보드에 프로토 타입 셀을 연결해야합니다. – developer

+0

어떤 작업을 수행해야합니다. 스토리 보드 또는 xib 파일의 셀 식별자를 사용하거나 'registerNib : forCellReuseIdentifier :,'또는 ' registerClass : forCellReuseIdentifier : – Abizern

+0

storyborad에 선언했습니다. 완료되었습니다. 더 자세히 설명해주세요. 옛 것과 현대의 차이는 무엇인가? – developer

관련 문제