1

UITableView を使用した私の見解では、nib にファイル所有者を指定してデリゲートとデータ ソースを設定しました。そして、私のクラス .h ファイルでは、以下のようなプロトコルに準拠しています...

例えば:

@interface test : UIViewController<UITableViewDelegate, UITableViewDataSource>
{
...
...
}

すべてが正常に機能しています...デリゲートメソッドはすべて適切に呼び出されています...私の質問は、.hに「UITableViewDelegate、UITableViewDataSource」を追加する理由です。それなしでも、私はそれらの電話を受けています。これの用途は何ですか?

ありがとう

4

6 に答える 6

5

私が推測する2つの理由から:

  1. これは、コンパイラがデータソースとデリゲート メソッドを実装することを通知するためのものであり、それらを実装しない場合、コンパイラは警告を出します。

  2. これらのメソッドのオートコンプリートは、ヘッダー ファイルにそのように追加した場合にのみ機能します

于 2013-08-21T07:28:28.183 に答える
2

.xib ファイルでデータソースを設定し、ファイルの所有者に委任する場合、それを行う必要はないと思います。

于 2013-08-21T07:31:37.017 に答える
1
See this url for reference..

https://developer.apple.com/library/ios/documentation/uikit/reference/UITableViewDelegate_Protocol/Reference/Reference.html

Also In this url we will use the methods frequently are

– tableView:heightForRowAtIndexPath:

  This will set Height

– tableView:didDeselectRowAtIndexPath:

 This will act as cellback for ui actions you are doing in table

– tableView:viewForHeaderInSection:

 usually we will add uiviews as table header

– tableView:viewForFooterInSection:

 usually we will add uiviews as table footer

– tableView:heightForHeaderInSection

 will set height to section header 

– tableView:heightForFooterInSection

 will set height to section footer
于 2013-08-21T07:31:52.507 に答える
1

UITableViewファイルの代わりにプログラムで作成または使用する場合は、.h ファイルでnib指定する必要があり ます。<UITableViewDelegate, UITableViewDataSource>

また、プログラムではなく .nib ファイルで UITableView を使用する場合は、.h ファイルで指定する必要はありません。

于 2013-08-21T07:29:30.493 に答える