UITableView 作为 inputAccessoryView 的高度为零

UITableView as inputAccessoryView has height of zero

我有两个 table 视图用作项目中的输入附件视图。一个是以编程方式创建的,并且显示得非常好。第二个是自定义 table 视图,其中包含在情节提要中制作的自定义单元格,并存储为视图控制器的 属性 作为强参考。

@property UITableView *firstTable; @property (strong, nonatomic) IBOutlet UITableView *secondTable;

它们都是在viewDidLoad中发起的,如下:

self.firstTable = [[UITableView alloc] initWithFrame:
                        CGRectMake(0, 0, self.view.bounds.size.width, 100) style:UITableViewStylePlain];
self.firstTable.delegate = self;
self.firstTable.dataSource = self;
self.firstTable.scrollEnabled = YES;
self.firstTable.rowHeight = 30;
self.firstTable.backgroundColor = [[SwagCommonFunctions alloc] colorWithHexString:@"f4ecea"];

self.secondTable.frame = CGRectMake(0, 0, self.view.bounds.size.width, 100);

它们在另一个函数中被设置为输入附属视图

[textView setInputAccessoryView:self.firstTableView];
    [textView reloadInputViews];

[textView setInputAccessoryView:self.secondTableView];
    [textView reloadInputViews];

firstTable 完美运行。 secondTable 永远不会加载,因为在 cellForRowAtIndexPath 时帧高度为零。如果框架高度手动设置为 100(宽度为全屏),原点为 numberOfRowsInSection 中的 (0,0),则 secondTable 会按预期显示正确的数据,但框架会遮挡整个键盘,而不是停留在正常的 inputAccessoryView 中地点。

如何正确设置 secondTable 的框架?

self.secondTable.autoresizingMask = UIViewAutoresizingNone;