1

1 つのクラスで複数の UITableView を使用していますが、デリゲートでそれらを分離することはできません。なぜこれが機能しないのですか:

- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    MenuHeader *header;
    if (tableView == myFirstTable) {
        header = [[MenuHeader alloc] initWithFrameAndTitel:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 40) :@"Text for first table"];
    }
    else if (tableView == mySecondTable) {
        header = [[MenuHeader alloc] initWithFrameAndTitel:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 40) :@"Text for second table"];
    }

    return header;
}

if ステートメントにブレークポイントを設定しましたが、ヘッダーが設定されません。同じことが起こります

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {}

@implementation の下でテーブルビューを宣言しました。

UITableView *myFirstTable;
UITableView *mySecondTable;
UITableView *myThirdTable;

次に、初期化子で:

myFirstTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 180)];
myFirstTable.dataSource = self;
myFirstTable.delegate = self;
[self addSubview:myFirstTable];


...

編集

より多くのコード:

@implementation TableStuff

@synthesize delegate = _delegate;

UITableView *myFirstTable;
UITableView *mySecondTalbe;
UITableView *myThirdTable;


- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code


        myFirstTable; = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 180)];;
        menuTable.dataSource = self;
        menuTable.delegate = self;
        [self addSubview:menuTable];


        mySecondTable = [[UITableView alloc] initWi....
        more init...





    }
    return self;
}
4

1 に答える 1

0

今のところ、テーブルビューにタグを追加し、tableview.tag を整数と比較することでこれを修正しました。2 つのテーブルビューの比較が機能しない理由はまだわかりません。

于 2013-02-07T16:45:21.607 に答える