2012-12-13 3 views
0

레이블이 포함 된 사용자 정의 셀을 만들었지 만 표시되지 않는 것보다 내 표보기에 추가했을 때 내보기 컨트롤러가 TableViewController IB를 사용하여 표보기를 설정하고 해당 표를 설정했습니다 델리게이트 및 데이터 소스 올바르게.내 사용자 정의 셀이 표시되지 않습니다

나는 이것을하고있는 중이 야 : tableView:numberOfRowsInSection 방법으로 설정 얼마나 많은 행

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    // Return the number of sections. 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    ExampleAppDataObject* theDataObject = [self theAppDataObject]; 
    return theDataObject.myAudio.count; 
} 


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

     static NSString *CellIdentifier = @"Cell"; 

     ExampleAppDataObject* theDataObject = [self theAppDataObject]; 

     NSString *destinationPath = [theDataObject.myAudio objectAtIndex:indexPath.row]; 

     NSArray *parts = [destinationPath componentsSeparatedByString:@"/"]; 

     NSString *filename = [parts lastObject]; 

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

     if (cell == nil) { 
      cell = [[AudioInfoCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier]; 
     } 

     cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; 

     cell.audioName.text = filename; 

     return cell; 

    } 
+0

은 numberOfSectionsInTableView를 수행하고있는 tableView는 : numberOfRowsInSection : 방법은 바로 숫자를 반환? – Julien

+0

코드 tableView : numberOfRowsInSection –

+0

코드를 사용하여 메서드를 게시하십시오. tableView – Rajneesh071

답변

0

먼저 확인

설정 한 후 울부 짖는 소리와 같은 정의 셀 ...

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    AudioInfoCell *cell = (AudioInfoCell *) [tableView dequeueReusableCellWithIdentifier:nil]; 


    // UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) 
    { 
     NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"AudioInfoCell" owner:self options:nil]; 

     for (id currentObject in topLevelObjects){ 
      if ([currentObject isKindOfClass:[UITableViewCell class]]){ 
       cell = (AudioInfoCell *) currentObject; 
       break; 

      } 
     } 
    } 

    ExampleAppDataObject* theDataObject = [self theAppDataObject]; 

    NSString *destinationPath = [theDataObject.myAudio objectAtIndex:indexPath.row]; 

    NSArray *parts = [destinationPath componentsSeparatedByString:@"/"]; 

    NSString *filename = [parts lastObject]; 

    cell.audioName.text = filename; 
    return cell; 
} 
+0

그 이유는 무엇입니까? for-in 루프는 표시되는 모든 셀에 대해 실행되며 사용자가 TV를 스크롤 할 때마다 실행됩니다. –

+0

그냥 때 세포가 nil 젠체하지 않습니다 .. 할당 코드 의이 흐름과 함께 Custem 세포를 사용하여 .. –

+0

이것은 "잡히지 않은 예외 'NSUnknownKeyException'이유로 인해 응용 프로그램을 종료하는 이유는 : '[ setValue : forUndefinedKey :] :이 클래스는 키 audioName에 대해 키 값 코딩을 준수하지 않습니다. ' " –

0

두 가지 확인 :

  1. 은 재사용 식별자는
  2. 올바른 번호
  3. 또한

당신의 numberOfRowsInSectionnumberOfSectionsInTableView 반환해야합니다 인터페이스 빌더에 무엇인지 일치하는지 확인 - 내가 사용하지 않는 :

if (cell == nil) { 
     cell = [[AudioInfoCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier]; 
} 

을을 인스턴스화 세포. 구현 한 하위 클래스 인 AudioCellTableViewCell에서 처리해야합니다. 내가 정의 셀의이 종류를 구현하는 방법의 예는 다음과 같습니다

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"FlightPickerCell"; 
    FlightPickerCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    cell.tripIDLabel.text = @"Some TripID"; 
    cell.hospitalLabel.text = @"Some Hospital"; 
    cell.cityLabel.text = @"Some City"; 
    return cell; 
} 
+0

모두 맞습니다. –

+0

하지만이 FlightPickerCell은 다른 데이터에 대해 재사용해야합니다. bcoz는 다른 종류의 데이터에이 셀을 재사용하고 싶습니다. –

+0

예. 그것은 서브 클래 싱 된 UITableViewCell을 구현 한 것입니다. –

관련 문제