*** Ошибка утверждения в - [UITableView _configureCellForDisplay: forIndexPath:]
Я использую ленточный загрузочный код tableview apple в моем проекте, но имеющий исключение в проекте. И ошибка - *** Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:]
, вот мой код, пожалуйста, помогите. Но он работает в другом проекте. У меня нет метода делегирования.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"LazyTableCell";
static NSString *PlaceholderCellIdentifier = @"PlaceholderCell";
NSUInteger nodeCount = [self.entries count];
if (nodeCount == 0 && indexPath.row == 0)
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:PlaceholderCellIdentifier];
cell.detailTextLabel.text = @"Loading…";
return cell;
}
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (nodeCount > 0)
{
AppRecord *appRecord = [self.entries objectAtIndex:indexPath.row];
cell.textLabel.text = appRecord.name;
if (!appRecord.appIcon)
{
if (self.mytable_view.dragging == NO && self.mytable_view.decelerating == NO)
{
[self startIconDownload:appRecord forIndexPath:indexPath];
}
cell.imageView.image = [UIImage imageNamed:@"Placeholder.png"];
}
else
{
cell.imageView.image = appRecord.appIcon;
}
}
return cell;
}
Ответы
Ответ 1
Потому что cellForRowAtIndexPath
возвращает значение nil
, а затем configureCellForDisplay
ожидает a UITableViewCell
. В раскадровке или XIB
нет ячейки, указанной с указанным идентификатором ячейки. Лучше проверьте написание идентификатора.
Ответ 2
Пожалуйста, проверьте наличие делегата.
Добавили ли вы делегат или нет?
UITableViewDelegate
, UITableViewDataSource
import UIKit
class UserFriendVC: UIViewController, UITableViewDelegate, UITableViewDataSource
{
override func viewDidLoad() {
super.viewDidLoad()
}
}
Ответ 3
вы должны добавить cellIdentifier из "Показать инспектор атрибутов" . Пожалуйста, подпарите, как показано ниже.
Сначала добавлен код ниже в ваш метод -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
delagate.
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
ResultCustomTableViewCell *cell = (ResultCustomTableViewCell *)[resultTableView dequeueReusableCellWithIdentifier:@"ResultTableViewCellIdentifier"];
...
//set the cell property
...
return cell;
}
а затем перейдите в "Показать инспектор атрибутов" , выбрав выбранный вид корневой ячейки.
![введите описание изображения здесь]()
И затем вставьте одно и то же имя идентификатора в раздел идентификатора в разделе "Показать инспектор атрибутов" . в этом случае я использую этот ResultTableViewCellIdentifier.
И еще один думаю. если вы используете пользовательскую ячейку точно так же, как этот сценарий, вы должны добавить ниже метод делегата. Поскольку ваша пользовательская высота ячейки может быть выше или меньше оригинальной высоты стола. И также вы должны зарегистрировать этот nib в viewDidLoad.
- (void)viewDidLoad {
[resultTableView registerNib:[UINib nibWithNibName:@"ResultCustomTableViewCell" bundle:nil] forCellReuseIdentifier:[ResultCustomTableViewCell reuseIdentifier]];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
CGFloat height = 0.0;
if (tableView == resultTableView){
height = 44.0f;
}
return height;
}
Надеюсь, это исправит вашу проблему.
Ответ 4
CellIdentifier
Уверен, что ваш cellForRowAtIndexPath
возвращает нуль.
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"LazyTableCell";
static NSString *PlaceholderCellIdentifier = @"PlaceholderCell";
NSUInteger nodeCount = [self.entries count];
if (nodeCount == 0 && indexPath.row == 0) {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:PlaceholderCellIdentifier];
if(cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:PlaceholderCellIdentifier] autorelease];
}
cell.detailTextLabel.text = @"Loading…";
return cell;
}
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
if (nodeCount > 0) {
AppRecord *appRecord = [self.entries objectAtIndex:indexPath.row];
cell.textLabel.text = appRecord.name;
if (!appRecord.appIcon)
{
if (self.mytable_view.dragging == NO && self.mytable_view.decelerating == NO)
{
[self startIconDownload:appRecord forIndexPath:indexPath];
}
cell.imageView.image = [UIImage imageNamed:@"Placeholder.png"];
}
else
{
cell.imageView.image = appRecord.appIcon;
}
}
return cell;
}
Вероятно, почему [UITableView _configureCellForDisplay:forIndexPath:]
не работает... потому что cellForRowAtIndexPath
возвращает нулевое значение, а затем configureCellForDisplay
ожидает UITableViewCell
.