1
我將uitableview單元格作爲子視圖添加到UIView中,這也是ViewController視圖的子視圖。但由於某種原因,當我將其初始化爲更小的尺寸時,UITableViewCell仍然在屏幕上延伸320像素。如何更改uitableviewcell的寬度
即使我將視角看成小視角,仍然保持320像素寬。我想知道它是否是一個層次結構問題?我覺得我的代碼是正確的,但也許我只是失去了一些東西......小
//..
// This UIView holds both custom UITableViewCell and UIButton and is placed at the top of the current UIView
cellContainer = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 200.0, 44.0)];
cellContainer.backgroundColor = [UIColor greenColor];
// Select all UITableViewCell
selectAllCell = [[UITableViewCell alloc] initWithFrame:CGRectMake(0.0, 0.0, 100.0, 7.0)];
selectAllCell.textLabel.text = @"Select all"; // Set text
// selectAllCell.accessoryType = UITableViewCellAccessoryCheckmark;
selectAllCell.backgroundColor = [UIColor redColor]; // set bg color
// Create non visible UIButton that sits over customTableviwecell wich allows you to set a selctor on the button press
UIButton *selectAllButton = [[UIButton alloc] initWithFrame:CGRectMake(0.0, 0.0, 200.0, 50.0)];
[selectAllButton addTarget:self action:@selector(selectAll:) forControlEvents:UIControlEventTouchUpInside];
// Add custom Cell and UIButton to cellContainer view
[cellContainer addSubview:selectAllCell];
[cellContainer insertSubview:selectAllButton aboveSubview:selectAllCell];
// Ass cellContainer to self.view
[self.view insertSubview:cellContainer atIndex:1];
//..
dag嘮叨吧!這太痛苦了......你認爲蘋果會皺着眉頭把細胞移到左邊,所以它稍微偏離視線,然後把細胞標題移到右邊。 – HurkNburkS
不能肯定地說。蘋果公司嚴格遵守接口指南。從聽起來像,你使用的是分組表格樣式,因爲這是唯一的邊框可見的單元格類型(普通表格類型只顯示頂部和底部邊框)。我的直覺是,只要所有的單元格邊界都可見,他們就不會太在乎你用什麼代碼來縮小它們。 –
好吧那麼這個問題怎麼樣,你可以有UITableView右側的部分滑塊的部分標題 – HurkNburkS