2011-08-11 2 views
1

내 자신의 gridview 구현 (tableview 패턴 기반)을 작성하는 중입니다. 테이블 뷰와 비슷한 데이터 소스 모델을 따랐지만 데이터 소스가 메시지에 응답하는지 확인하면 호출이 항상 실패합니다.respondsToSelector가 항상 실패합니다.

중단 점을 넣고 실행을 시도했지만 respondsToSelector에 대한 호출을 놓치 려했습니다. 내가 시도하는 것은 아무것도 작동하지 않는 것 같습니다. 내가 여기서 무엇을 놓치고 있니? 미리 감사드립니다

GridView.h

... 
    @protocol GridViewDataSource 
    - (NSInteger) numberOfRowsForGridView:(GridView *)gridView; 
    - (NSInteger) numberOfColumnsForGridView:(GridView *)gridView; 

    - (GridViewCell *) cellForRow:(NSInteger) row column:(NSInteger)column; 
    @end 

GridView.m

... 
    #pragma mark datasource methods 
    -(NSInteger)numberOfRowsForGridView 
    { 
     if([dataSource respondsToSelector:@selector(numberOfRowsForGridView:)]) 
      return [dataSource numberOfRowsForGridView:self]; 
     // NSLog(@"Failed, dataSource does not implement properly"); 
     return 0; 
    } 

    -(NSInteger)numberOfColumnsForGridView 
    { 
     if([dataSource respondsToSelector:@selector(numberOfColumnsForGridView:)]) 
      return [dataSource numberOfColumnsForGridView:self]; 
     return 0; 
    } 

    -(GridViewCell *)cellForRow:(NSInteger)row column:(NSInteger)column 
    { 
     if([dataSource respondsToSelector:@selector(cellForRow:column:)]) 
      return [dataSource cellForRow:row column:column]; 
     return nil; 
    } 

GridViewAppDelegate.h

... 
    @interface GridViewAppDelegate : NSObject <UIApplicationDelegate, GridViewDataSource> 
    ... 

GridViewAppDelegate.m

#pragma mark datasource methods 
    -(NSInteger)numberOfRowsForGridView:(GridView *)gridView 
    { 
     return 1; 
    } 

    -(NSInteger)numberOfColumnsForGridView:(GridView *)gridView 
    { 
     return 1; 
    } 

    -(GridViewCell *)cellForRow:(NSInteger)row column:(NSInteger)column 
    { 
     CGRect frame = [view bounds]; 


     GridViewCell *cell = [[GridViewCell alloc]initWithFrame:frame]; 
     return cell; 
    } 

답변

1

dataSource 객체 nil인가? (숫자 0과 nil 개체에 대한뿐만 아니라)

부울 결과 에 대한 NO를 반환합니다 nil에 전송 된 모든 메시지.

+0

Arg, 나 자신을 믿을 수 없다. 데이터 소스가 재설정 될 때가 아니라 init 함수에서 뷰에 대한 데이터 만로드했습니다. 정말 고맙습니다. – botptr

0

dataSource이 nil이 아닌지 확인 했습니까?

관련 문제