2011-08-11 10 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ですか?

nilに送信されたメッセージは、ブール結果(番号0、及び同様にオブジェクトのnilためNOを返します。

+0

Arg、私は自分自身を信じることができません。私は、データソースがリセットされたときではなく、init関数内のビューのデータのみをロードしていました。どうもありがとうございます。 – botptr

0

dataSourceがnilではないことを確認しましたか?

関連する問題