2016-08-13 19 views
1

我想知道的是,它是必需的在viewDidLoad和UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"myidentifier"];在cellForRowAtIndexPath?[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"myidentifier"];?對於iOS 10.0?在iOS 10中爲tableviewcell編寫registerWithClass或registerWithNib是否強制?

因爲在iOS 10.0測試版中,當我沒有註冊類時它殺死了應用程序。但它可以在iOS的早期版本中使用,無需註冊。

謝謝大家。

+0

稱它是'[self.tableView的registerClass:[UITableViewCell類,] forCellReuseIdentifier:@ 「myidentifier」 ];'在ROWATINDEX的內部細胞 –

+0

您使用Xib或故事板嗎? – Harsh

+0

No Just Class。和@ Anbu.Karthik它工作正常,當我註冊在viewdidload。我的問題是這是強制性的?如果是,那爲什麼? –

回答

1

不,不是強制性的。

如果您正在使用Storyboard,則無需registerClass,因爲即使自定義類,故事板設置已將單元格與其類相關聯。 (你必須在單元屬性中的「自定義類」窗格中設置類的類型)。

上的Xcode 7.3測試objC:

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

迅速3/Xcode中8:

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

是的,你是正確的感謝ingconti。 –

相關問題