我有一个关于使用 Xcode 6.1 + iOS SDK 8.1 运行的 UITableview 的问题。
我有一个简单的单视图应用程序,当我使用情节提要创建表格视图时发生了一些奇怪的事情。
在我的 viewDidLoad 中,我编写了以下代码:
UITableView *tableView = (id)[self.view viewWithTag:1];
[tableView registerClass:[NameAndColorCell class] forCellReuseIdentifier:CellIdentifier];
添加/编辑:
UITableView *tableView = (id)[self.view viewWithTag:1];
NSLog(@"Table View Tag = %ld", (long)tableView.tag);
[tableView registerClass:[NameAndColorCell class] forCellReuseIdentifier:CellIdentifier];
UIEdgeInsets contentInset = tableView.contentInset;
contentInset.top = 20;
[tableView setContentInset:contentInset];
但是tableView总是nil,最终导致我的App崩溃了。
我检查了我的视图控制器的视图,“使用自动布局”和“使用大小类”都已启用。
在我禁用“使用大小类”后,一切恢复正常。我的意思是,tableView 已成功创建。
有没有人遇到过同样的问题?这是来自 Xcode 的错误吗?还是我犯了一些错误?
请帮助我,非常感谢!
最好的问候, 瑞