1つのアプリケーションに2つのインスタンスのUITableViewがあります。問題は、各テーブルの表示方法を定義する方法がわかりません。ここでは、コードです:2つのTableViewを扱う方法
.H:
{
NSArray *array1;
NSArray *array2;
IBOutlet UITableView *table1;
IBOutlet UITableView *table2;
}
.M:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [array1 count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = [array1 objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
}
このコードは、ちょうど一つのテーブルのために働いています。私はarray2で他のテーブルを設定する方法を知らない。アイデアはありますか?
リストされたすべての委任されたメソッドには、tableViewパラメータがあります。テーブルビューがtable1かtable2かを比較して、それに応じて動作するかどうかを調べることができます。 – user523234