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 添加一个标签并将 tableview.tag 与一个整数进行比较来解决这个问题。仍然不知道为什么比较两个表视图不起作用。

于 2013-02-07T16:45:21.607 回答