1

スクロールビューに4つのUITableViewを追加し、それらにいくつかの異なる配列を入力したいと思います(たとえば、それぞれに1つの配列があるとします)。このスクロールビューも自分に追加しましたself.view(UIViewControllerクラスでこれを行います)。テーブルビューにデータを入力するにはどうすればよいですか?

詳細:

これがスクリーンショットです。 ここに画像の説明を入力してください

これが私のUIViewControllerClassのインターフェースです

#import <UIKit/UIKit.h>

@interface MainMenu : UIViewController<UITableViewDelegate>

@property (retain, nonatomic) IBOutlet UIScrollView *scrollView;
@property (retain, nonatomic) IBOutlet UITableView *group1;
@property (retain, nonatomic) IBOutlet UITableView *group2;
@property (retain, nonatomic) IBOutlet UITableView *group3;
@property (retain, nonatomic) IBOutlet UITableView *group4;

@end//i drag/dropped from IB, so there is no problem with synthesizes..

これらのテーブルビューにさまざまな配列を入力したいのですが、この状況を処理する方法は..?どうもありがとう

追記; 私はこのようなことを試しましたが、効果はありませんでした:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [group1 dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    NSArray *array=[NSArray arrayWithObjects:@"one",@"two",@"tree", nil];
    cell.textLabel.text = [array objectAtIndex:indexPath.row];
    return cell;

}
4

1 に答える 1

1

おい、最初に4つのテーブルすべてのデリゲートとデータソースのuiviewcontrollerを作成します。その後、各テーブルに異なるタグを割り当てます..次に、デリゲートとデータソースプロトコルを追加します...そして、実装します通常の uitableviewcontroller のような datasource および delegate メソッド...これらのメソッドはすべて Uitableview パラメーターを受け取るため、このテーブル ビューのタグを次のようにテストします。

...

if (tableView.tag == 10) {
//implement the table 1
NSArray *array=[NSArray arrayWithObjects:@"one",@"two",@"tree", nil];
cell.textLabel.text = [array objectAtIndex:indexPath.row];

} else if (tableView.tag == 20) {
//implement the table 2
} else if (tableView.tag == 30) {
//implement the table 3
} else if (tableView.tag == 40) {
//implement the table 4
}

return cell;

このようにして、同じ方法を使用してすべてのテーブル ビューを実行します。

于 2012-04-19T12:06:46.883 に答える