iOS10 中的tableview cell 必须写register With Class 或registerWithNib 吗?

Is it compulsory to write registerWithClass or registerWithNib for tableviewcell in iOS 10?

我想知道在 viewDidLoad 中 [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"myidentifier"]; 以及在 cellForRowAtIndexPath 中 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"myidentifier"]; 是强制性的吗? iOS 10.0?

因为在 iOS 10.0 beta 中,当我没有注册类时它会杀死应用程序。但它可以在 iOS 的早期版本中运行而无需注册。

谢谢大家

不,不是强制性的。

如果您正在使用情节提要,则无需注册Class,因为情节提要设置已经将单元格与其 Class 相关联,即使自定义 class 也是如此。 (您必须在 属性 单元格的 "custom class" 窗格中设置 class 类型。

在 Xcode 7.3 objC:

上测试
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    CustomTableViewCell *cell = (CustomTableViewCell*) [tableView dequeueReusableCellWithIdentifier:@"CELLID" forIndexPath:indexPath];

在swift3/Xcode8:

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "CELLID", for: indexPath) as! CustomTableViewCell
..