在Objective-C工程中:
按我使用OC的習慣,通過nib給UITableView注冊一個Cell時,通常nib的名字是用其對應class的類名:NSStringFromClass([YourTableViewCell class])
來處理的,這樣不容易因為字符串寫錯而出錯。
但當YourTableViewCell.xib關聯的類是YourTableViewCell.swift時,NSStringFromClass([YourTableViewCell class])
得到的字符串就不是“ YourTableViewCell”
,而是“ 你的工程名字.YourTableViewCell”
。這種情況就會發生奔潰,當然這是在編譯時候就能發現的錯誤。
那我們怎么解決這種情況呢?
廢話,寫字符串呀!好好檢查字符串是否寫對,最好直接復制。
[self.tableView registerNib:[UINib nibWithNibName:@"YourTableViewCell" bundle:[NSBundle mainBundle]]
forCellReuseIdentifier:@"YourTableViewCell"];