各 tam tableView を異なるデータで表示するために tableView を使用しています。すべての tableView デリゲートを使用してインターフェイスに戻ると*list
、前のビューに基づいてデータ (フィールドを含むさまざまな配列) に興味をそそられます
if(select = names )...
list = myData.Names;
if (select = workers)...
list = myData.Workers;
等々...
そして、私が使用するテーブルデリゲートで:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [list count];
}
しかし、表のセルのオブジェクトを初期化するときに、セルに適切なオブジェクトを正確に設定するにはどうすればよいですか。今私が使用するハードコード:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MyIdentifier"] autorelease];
}
//HARD-CODED
names *s = [list objectAtIndex:indexPath.row];
cell.textLabel.text = names.firstName;
cell.detailTextLabel.text=s.lastName;
return cell;
}
を設定するとき、毎回正しいオブジェクトにキャストlist
する方法を知るにはどうすればよいですか? workers
何百万ものif
?
たとえば、
if (select = workers)...
list = myData.Workers;
[list count] は正しい数値を返しますが、リストに基づいてデータを表示したいのですが、それをキャストして自動的にワーカーを宣言するにはどうすればよいですか
workers *s = [list objectAtIndex:indexPath.row];