[英]Change UITableViewStyle to Plain programmatically in Swift?
[英]Change UITableViewStyle & cells programmatically - Made in Storyboard, Mod in Code
此實用程序應用程序中的視圖控制器類(UITableViewController的子類)用於顯示4個表視圖,其中3個是通過導航控制器輸入的。 在情節提要中,樣式已設置為UITableViewStyleGrouped
。
問題:是否可以通過編程方式更改為Style Plain
以使用索引並釋放一些屏幕空間來顯示索引? 我嘗試了其他SO問題的建議,但未成功在init
和viewDidLoad
中對其進行修改。
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.title = self.title;
if ([[self parentViewController] isKindOfClass:[UITabBarController class]]) {
[self getNewDataForDate:nil];
self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
}
}
編輯1:真正的問題不在上面的代碼。 使用原型單元(以分組形式顯示在此處)更改情節提要生成的表視圖的“樣式”,必須需要其他一些mod才能進行編碼。 在這嗎
static NSString *CellIdentifier = @"ListCell";
DetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
結果是此錯誤:
Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:]
初始化表視圖時,可以設置表樣式(請參閱initWithFrame:style :)。 之后,您將無法修改樣式。 (這來自Apple的文檔 )。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.