dequeue Reusable Cell WithIdentifier:에 대한 개인적 이해

2626 단어
Table Data Source Methods에서 필요한 방법 중 하나table View: cellForRowAtIndexPath: 코드가 항상 포함되어 있습니다.
static NSString *FirstLevelCell = @"FirstLevelCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
                             FirstLevelCell];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]
                initWithStyle:UITableViewCellStyleDefault
                reuseIdentifier: FirstLevelCell];
    }

첫 번째 줄은 문자열 표식이 설정되어 있습니다.
두 번째 줄부터 관건은 공식 문서에서 방법dequeue Reusable Cell With Identifier:에 대한 설명을 살펴보는 것이다.
For performance reasons, a table view'€™s data source should generally reuse UITableViewCell objects when it assigns cells to rows in its tableView:cellForRowAtIndexPath: method. A table view maintains a queue or list of UITableViewCell objects that the data source has marked for reuse. Call this method from your data source object when asked to provide a new cell for the table view. This method dequeues an existing cell if one is available or creates a new one using the class or nib file you previously registered. If no cell is available for reuse and you did not register a class or nib file, this method returns nil. If you registered a class for the specified identifier and a new cell must be created, this method initializes the cell by calling its initWithStyle:reuseIdentifier: method. For nib-based cells, this method loads the cell object from the provided nib file. If an existing cell was available for reuse, this method calls the cell’s prepareForReuse method instead.
번역하면 다음과 같다.
성능 때문에, 하나의 테이블 보기의 데이터 원본은 다시 사용할 수 있는 테이블 보기 단원의 대상을 사용해야 한다.테이블 보기가 복원 가능한 단원의 대기열이나 목록을 유지하고 있습니다.새로운 단원을 표시할 때 이 방법을 사용합니다. 이 방법은 이미 존재하는 단원을 열거합니다.다시 사용할 단원이 없으면 nil로 돌아갑니다.
솔직히 잘 모르겠어요.아니면 테이블 보기의 생명주기로 말하자면, 처음에는 대기열을 비워 두었다가 dequeue Reusable Cell With Identifier를 호출합니다. nil로 되돌아갈 것입니다.그런 다음 initWithStyle:reuseIdentifier: 방법을 호출하여 복용 기호를 생성하고 표의 보기 단원을 표시합니다.화면이 가득 차면 테이블 보기를 스크롤하면 한쪽 단원이 화면에서 이동합니다. 이 단원은 복용 가능한 단원 대기열에 들어갑니다. 그리고prepareForReuse 방법을 사용해서 곧 나열될 단원을 준비합니다. dequeueReusable CellWithIdentifier: 복용 가능한 단원 대기열에서 복용 가능한 단원을 열거합니다.
테이블 보기에는 서로 다른 유형의 단원이 있을 수 있으며, 복용은 같은 유형의 단원에서 발생한다.대기열에 몇 개의 단원이 있는지에 대해 이 시스템은 스스로 제어한다. 만약 메모리가 부족하면 동적으로 일부를 방출하고 조건이 개선될 때 다시 이 단원을 가져와 복용하기 편리하게 한다.복용 가능한 단원이 없는 극단적인 경우, initWithStyle:reuseIdentifier: 를 호출하여 새로운 단원을 생성합니다.표시도의 메커니즘을 이해하고 사고를 엄격한 대열 메커니즘에 정할 수 없기 때문에 일부 동태적인 요소를 고려해야 한다.
이외에if문장 아래의 조작은 리모델링이라고 할 수 있고if문장의 조작은 반드시 새로 만들어야 한다.
주요 참조:
http://blog.csdn.net/tongzhitao/article/details/7843897
애플 공식 문서

좋은 웹페이지 즐겨찾기