2012-05-21 4 views
0

저는 iPhone 개발을 처음 사용합니다. 스토리 보드와 함께 xCode 4.2를 사용하고 있습니다. 내 테이블 뷰에 여러 개의 uilabels를 표시하는 셀을 가져 오려고합니다. 그들은 단지 내 시뮬레이터에 나타나지 않습니다. 원래 cell.textLabel이 표시됩니다.맞춤 셀의 라벨이 표시되지 않습니다.

내가 한 일은 다음과 같습니다. UITableViewCell을 확장하는 새로운 customcell.h/.m 파일을 만들었습니다. 클래스에 인스턴스 변수를 추가했습니다. 스토리 보드에 가서 tableviewcell의 ID 검사관 클래스에서 customcell을 가리 키도록 변경했습니다. 나는 끌어서 일부 UI 라벨을 새 셀에 떨어 뜨 렸습니다. 그런 다음 연결 관리자에서 "plus"아이콘을 선으로 드래그하여 새 uilabels에 인스턴스 변수에 연결했습니다.

시뮬레이터를 실행할 때 새로운 ui 레이블이 표시되지 않습니다. 원래 uilabel은 cell.textLabel입니다. 프로그래밍 방식으로 새 레이블 인 cell.mylabel1, cell.mylabel2 등을 가져올 수 있지만 표시되지 않습니다.

추가 정보 이것은 내 tableviewcontroller의 cellForRowAtIndexpath 함수입니다. 에서 "이 속성을 속성"에 식별자를 지정

첫째, 다윗이 언급했듯이

static NSString *CellIdentifier = @"Cell"; // this was the error, i needed to change this to CustomCell, or whatever it is in my storyboard 

CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

if (cell == nil) { 
    cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
} 
cell.mylabel1.text = @"hello"; // doesn't appear in simulator 
cell.textLabel.text = @"world"; // does apepar in the simulator 
+1

어떻게'cellForRowAtIndexPath :'에서 당신의 세포를 만들고/dequeueing하고 있습니까? 스토리 보드에 reuseIdentifier를 설정 했습니까? –

+0

아, 네가 괜찮다면 스토리 보드에 cellidentifier를 설정하는 것을 잊어 버렸고, 'cellforRowatIndexPath' 함수에서 그것을 잊어 버렸다. 지금 작동 – John

답변

2

, 여기에 하나의 누락 된 부분은 스토리 보드에 지정된 셀의 식별자를 참조 할 필요가있다 스토리 보드. UITableViewCell을 선택하고 식별자 "ExampleCell"(예 :)을 추가하여이 작업을 수행 할 수 있습니다. 둘째, CustomCell을 만들 때 코드에서이 식별자를 참조하십시오.

static NSString *CellIdentifier = @"ExampleCell"; 
CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
} 
관련 문제