同じビューに 2 つの UITableView がありますが、viewDidLoad
メソッドで異なるデータをどのように入力するかという質問がありますか? ありがとう。
3 に答える
0
すべてのデリゲートおよびデータソースプロトコルメソッドは、常に、必要なtablesViewへのポインターを渡します。それぞれの方法でどちらが意味されているかを確認するためにifを実行するだけです。
于 2011-06-20T05:02:03.467 に答える
0
それらを
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
その関数では、tableView を比較してそれがどのテーブルであるかを確認し、そのテーブルに適切なデータをロードできます。
//Assume the following property
@property (nonatomic, retain) NSDictionary *myData;
これをコードファイルに追加します
- (NSDictionary) myData
{
if (myData == nil) //Notice I am accessing the variable, not the property accessor.
{
NSString *filePath=[[NSBundle mainBundle] pathForResource:@"someName" ofType:@"plist"];
myData = [[NSDictionary dictionaryWithContentsOfFile:filePath] retain];
}
return myData;
}
次に、 self.myData プロパティにアクセスすると、まだ開いていない場合は開きます。
于 2011-04-21T20:39:34.117 に答える
0
質問の plist 部分に答えるには:
NSString *filePath=[[[NSBundle mainBundle] pathForResource:@"someName" ofType:@"plist"] retain];
NSDictionary *dict = [[NSDictionary dictionaryWithContentsOfFile:filePath] retain];
したがって、これらのうちの 2 つ (テーブルごとに 1 つ) を使用し、2 つの tableView を使用するだけです。
于 2011-04-21T22:58:40.190 に答える