[英]Table View out of the window screen iOS objective C
我為故事板上的文本字段設置了約束。 我想使用以下代碼在文本字段下創建一個表格視圖。 設置類似於textfield.frame.size.width
的寬度會將tableView完全移出屏幕,為什么? 請幫忙。
-(void)cofigureAutoComTableView
{
autocompleteTableView = [[UITableView alloc] initWithFrame:CGRectMake(self.txtActivity.frame.origin.x,self.txtActivity.frame.origin.y+32,self.txtActivity.frame.size.width, 200) style:UITableViewStylePlain];
autocompleteTableView.delegate = self;
autocompleteTableView.dataSource = self;
autocompleteTableView.scrollEnabled = YES;
//autocompleteTableView.
autocompleteTableView.hidden = YES;
[self.view addSubview:autocompleteTableView];
CALayer *layer = autocompleteTableView.layer;
[layer setMasksToBounds:YES];
[layer setCornerRadius: 4.0];
[layer setBorderWidth:1.0];
[layer setBorderColor:[[UIColor blackColor] CGColor]];
}
看起來很像,因為當textview這么長時您正在調用函數,因此請在viewDidAppear
使用它
[self cofigureAutoComTableView];
你可以試試
-(void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
if(once)
{
once = NO;
[self conf];
}
}
問題在於,在viewDidLoad中,框架不是最終形式。 只有在viewDidAppear中,框架才是最終的。
在這種情況下,最好的解決方案是在viewDidLayoutSubviews中更新autocompleteTableView的框架。
每當更新viewController的視圖框架時,都會調用viewDidLayoutSubviews。
-(void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
autocompleteTableView.frame = CGRectMake(self.txtActivity.frame.origin.x,self.txtActivity.frame.origin.y+32,self.txtActivity.frame.size.width, 200);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.