0

我有两个UITableView并排显示。UITextView在视图的最右侧还有一个。

所以第UITableView一个宽度为 300px 的位于最左侧。第二个UITableView位于视图的中心。该表格的宽度为 150 像素。然后UITextView, 它具有动态宽度(因为不同方向有不同的宽度),正如我之前提到的,它位于最右侧。

问题是 2UITableViews的大小因方向而异。

这就是我初始化它们的方式:

UITableView *bookTable = [[UITableView alloc]initWithFrame:CGRectMake(0, 102, 300, self.view.bounds.size.height - 102)];
[bookTable setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleRightMargin];

UITableView *pageTable = [[UITableView alloc]initWithFrame:CGRectMake(bookTable.bounds.size.width, 102, 150, self.view.bounds.size.height - 102)];
[pageTable setAutoresizingMask:UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin];

UITextView *notesView = [[UITextView alloc]initWithFrame:CGRectMake((bookTable.bounds.size.width + pageTable.bounds.size.width), 102, self.view.bounds.size.width - (bookTable.bounds.size.width + pageTable.bounds.size.width), self.view.bounds.size.height - 102)];
[notesView setAutoresizingMask:UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin];

如您所见,我autoresizingMask在它们每个上都设置了。发生的事情是 bookTable 的纵向宽度为 300px,但是当我转向横向时,宽度变为 400px。

autoresizingMask负责人对此负责吗?如果是这样,我应该如何解决这个问题?

4

1 回答 1

0

I had a similar problem like this. You might need to post some more code, but you should use 'UITableViewDataSource' method:

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

This way you can add your textfields to the cells subview and then set the autoresizing.

[cell.contentView addSubview:textField];            
[cell setAutoresizesSubviews:YES]; 
于 2012-10-23T10:00:35.717 回答