我是新來的ios,我有以下問題。ios增加/減少表格大小
我想根據表視圖中元素的數量增加和減少tableview的高度。如果在輸入時客戶端輸出3或3個以上的元素,我想看到一個比默認值大2行的tableview。當輸出中元素的數量是2或1時,我會看到默認的表格視圖高度。寬度將是相同的。這個怎麼做?
這是我的代碼:
if (inputList.count>2)
{
CGRect bounds = [self.tableView bounds];
[self.tableView setBounds:CGRectMake(bounds.origin.x,
bounds.origin.y,
bounds.size.width,
bounds.size.height + 50)];
CGRect tableFrame = [ self.predictiveDialog frame];
tableFrame.size.height=75;
[self.tableView setFrame:tableFrame];
}
else
{
NSLog(@"decrease size");
[self.tableView setBounds:CGRectMake(bounds.origin.x,
bounds.origin.y,
bounds.size.width,
bounds.size.height - 50)];
CGRect tableFrame = [ self.predictiveDialog frame];
tableFrame.size.height=44;
[self.tableView setFrame:tableFrame];
}
在這種情況下,實現代碼如下寬度爲OK,並且高度是確定當輸入元件進來,但根據無在inputlist元素 - 的tableview中被向上移動,並在ios屏幕上。爲什麼?
你想增加表視圖的框架或表視圖中的單元格的高度? –
我想增加tableview的高度。 –
請參考我的答案並相應地設置邊界。你的代碼中的「邊界」是指什麼?我的意思是哪個視圖。我猜想它的一些其他觀點 –