0

탐색 템플릿을 사용하여 다중보기 응용 프로그램을 만들려고합니다. 상단에 다른보기 (이미지보기, 레이블 등)가있는 초기보기의 맨 아래에 테이블이 필요합니다.RootController를 사용하여 다중보기 TableView

원본으로 RootViewController.xib를 수정하여 tableview의 크기를 조정하고 이미지보기를 추가했지만 풀 사이즈 표를 제외하고는 아무것도 표시되지 않았습니다.

그래서 RootViewController.xib를 수정하여 UIView를 추가 한 다음 해당 뷰에 UITableView 및 UIImageView를 추가했습니다. tableView에 IBOutlet을 추가했습니다. 내 RootViewController.xib 파일의 소유자 (RootViewController)보기 및 테이블보기 콘센트 연결이 있습니다. UITableView를 마우스 오른쪽 단추로 클릭하면 File 's Owner에 대한 참조 콘센트가 나타납니다. UIView를 마우스 오른쪽 단추로 누르면 File 's Owner에 대한 참조 콘센트가 나타납니다. (코드에서 수정하지 않으므로 UIImageView에 대한 콘센트가 없기 때문에 필요합니까?). 나는 응용 프로그램을 시작할 때

그러나, 그것은 메시지와 함께 충돌 :

'NSInternalInconsistencyException', 
reason: '-[UITableViewController loadView] loaded the "RootViewController" nib but didn't get a UITableView.' 

확실하지 왜, 어떻게 해결. 어떤 도움이라도 대단히 감사합니다. (NSIndexPath *) indexPath {

정적는 NSString * QuizIdentifier = @ "QuizIdentifier"

  • (있는 UITableViewCell *)를 tableView : (jQuery과 *)를 tableView cellForRowAtIndexPath 여기

    는 cellForRowAtIndexPath 방법이며 ;

    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier : QuizIdentifier];

    경우 (셀 == 닐) {

    cell = [[[UITableViewCell alloc] 
    
         initWithStyle:UITableViewCellStyleDefault 
    
         reuseIdentifier:QuizIdentifier] 
    
         autorelease]; 
    

    }

    있는 UIImage _image * = [있는 UIImage imageNamed : @ "icon.png"];

    cell.imageView.image = _image;

    NSInteger row = [indexPath row];

    cell.textLabel.text = [_categories objectAtIndex : row];

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    복귀 셀; }

OK, 여기 간다 : 당신은 탐색 기반의 iOS 앱을 만들 때, 엑스 코드는 RootViewController에게 UITableViewController의 서브 클래스를 만들기 때문에

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

     static NSString *QuizIdentifier = @"QuizIdentifier"; 

     UITableViewCell *cell = 
     [tableView dequeueReusableCellWithIdentifier:QuizIdentifier]; 

     if (cell == nil) { 
      cell = [[[UITableViewCell alloc] 
        initWithStyle:UITableViewCellStyleDefault 
        reuseIdentifier:QuizIdentifier] 
        autorelease]; 
     } 

     // Configure the cell. 

     UIImage *_image = [UIImage imageNamed:@"icon"]; 
     cell.imageView.image = _image; 

     NSInteger row = [indexPath row]; 
     cell.textLabel.text = [_categories objectAtIndex:row]; 

     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

     return cell; 
    } 

답변

0

당신은 그 오류가 있습니다. UITableView을 보통 UIView과 결합하면 하위 클래스는 더 이상 UITableViewController 클래스를 준수하지 않습니다. 따라서 RootViewController.m과 .h 파일에서 UITableViewControllerUIViewController으로 변경하십시오. init 메소드에서 몇 가지 다른 사항을 변경해야 할 수도 있지만, 이제부터 시작하겠습니다.

이 시도 :

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

    NSLog(@"\n\nI'm in Root/cellForRowAtIndexPath"); 

    static NSString *QuizIdentifier = @"QuizIdentifier"; 

    UITableViewCell *cell = 
    [tableView dequeueReusableCellWithIdentifier:QuizIdentifier]; 

    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] 
       initWithStyle:UITableViewCellStyleDefault 
       reuseIdentifier:QuizIdentifier] 
       autorelease]; 
     UIImage *_image = [UIImage imageNamed:@"icon"]; 
     cell.imageView.image = _image; 
     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    } 

    // Configure the cell. 
    NSInteger row = [indexPath row]; 
    cell.textLabel.text = [_categories objectAtIndex:row]; 

    NSLog(@" We are at row %i with label %@ ", row, cell.textLabel.text); 

    return cell; 
} 
+0

OK, 나는 RootViewController.h에있는 UIViewController에있는 UITableViewController를 변경; 이제 빈 테이블처럼 이미지보기가 표시됩니다. 네비게이션 기반 앱이 아닌 일반 뷰 기반 앱처럼 보입니다. 이 경우에도 탐색 템플릿을 사용해야하는 이유가 있습니까? – Namhcir

+0

그럼, 여전히 문제가 있습니까, 아니면 지금 작동합니까? – edc1591

+0

OK, 지금까지 작동합니다. 그러나 셀 속성을 표시하는 데 문제가 있습니다. [array objectAtIndex : row] 메시지에서 cell.textLabel.text를로드하면 올바르게 표시됩니다. 그러나 액세서리 유형이나 이미지를 표시하려고 시도 할 때 표시되지 않습니다. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; cell.imageView.image = [UIImage imageNamed : @ "myImage.png]; 따라서 이러한 속성을 표시 할 수 없습니다. 모든 아이디어를 크게 높이 평가했습니다. – Namhcir