简体   繁体   English

cellForRowAtIndexPath:被调用但没有显示在tableview中

[英]cellForRowAtIndexPath: gets called but nothing shows up in tableview

I have an ordinary tableview with custom cells, working perfectly on iOS 6.0 but after upgrading the app to iOS 10, scattered problem arises.我有一个带有自定义单元格的普通 tableview,在 iOS 6.0 上完美运行,但在将应用程序升级到 iOS 10 后,出现了分散的问题。

Note: The app works as expected on iPhone 5, both on simulator and on a real device.注意:该应用程序在 iPhone 5 上按预期运行,无论是在模拟器上还是在真实设备上。 All devices are running iOS 10.2 but iPhone 6 and above has the issues described below.所有设备都运行 iOS 10.2,但 iPhone 6 及更高版本存在以下问题。

Some tableviews work fine just like before, while one of the tableViews always shows exactly 1 cell (even tough cellForRowAtIndexPath is called 7 times) and another table shows no cells at all despite cellForRowAtIndexPath getting called twice.一些 tableviews 像以前一样工作正常,而 tableViews 之一总是显示恰好 1 个单元格(即使是艰难的 cellForRowAtIndexPath 也被调用了 7 次),另一个表根本没有显示任何单元格,尽管cellForRowAtIndexPath被调用了两次。

I am wondering why the method is called if the tableview does not care to display the result?我想知道如果 tableview 不关心显示结果,为什么会调用该方法?

I am at a total loss as to what is going on and how to fix it.我完全不知道发生了什么以及如何解决它。 Been at it for a day with no progress at all.搞了一天,一点进展都没有。 I have tried cleaning and running different builds and can not get the affected tableviews to behave correctly.我尝试清理和运行不同的构建,但无法让受影响的 tableview 正常运行。 I don't know what to try next?我不知道接下来要尝试什么? Any help is appreciated, thanks!任何帮助表示赞赏,谢谢!

Ok since you need some code here is a part of it that is not that sensitive.好的,因为您需要一些代码,这是其中不那么敏感的一部分。 DataSource:数据源:

- (void)viewDidLoad
{
    [super viewDidLoad];

    NOSUserInfo2 *userInfo = [S24SharedUserHandler currentUser];

    dataSource = [NSMutableArray arrayWithArray:[userInfo children]];

    if([userInfo student] || [userInfo teacher])
    {
        [dataSource insertObject:userInfo atIndex:0];   
    }

    self.contentSizeForViewInPopover = CGSizeMake(250, 45*dataSource.count-1);
    self.tableView.backgroundColor=[UIColor colorWithWhite:0.95f alpha:1];
    self.tableView.scrollEnabled=NO;
    [self.tableView registerNib:[UINib nibWithNibName:@"NOSPersonSelectorCell" bundle:nil] forCellReuseIdentifier:@"PersonPopoverCell"];
}

This gets called 2 times:这被称为 2 次:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"PersonPopoverCell";
    NOSPersonSelectorCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    cell.selectionStyle=UITableViewCellSelectionStyleNone;

    cell.textLabel.font = [UIFont fontWithName:@"HelveticaNeue-Medium" size:15];

    cell.textLabel.backgroundColor=[UIColor clearColor];

    NSObject *dataObject = [dataSource objectAtIndex:[indexPath row]];

    if ([dataObject isKindOfClass:[NOSUserInfo2 class]]) {
        cell.textLabel.text = [(NOSUserInfo2 *)dataObject name];
        cell.pk = [(NOSUserInfo2 *)dataObject personPK];
    }
    else {
        cell.textLabel.text = [(NOSChild2 *)dataObject childName];
        cell.pk = [(NOSChild2 *)dataObject childPK];
    }

    cell.textLabel.textColor = [UIColor colorWithWhite:0.18f alpha:1];

    //NSLog(@"%d", [S24SharedUserHandler selectedPk]);
    cell.checkmark.hidden=cell.pk!=[S24SharedUserHandler selectedPk];
    return cell;
}

And the result is that the tableview is empty.结果是tableview是空的。

New information 11 Jan 2017 The app works when testing on phone, but not on simulator.新信息 2017 年 1 月 11 日 该应用程序在手机上测试时有效,但在模拟器上无效。 I still have no idea what is wrong and am really dissapointed in the downvotes I am still getting for asking this question.我仍然不知道出了什么问题,并且对我仍然因为提出这个问题而得到的反对票感到非常失望。 I would appreciate if somebody can explain why they think it is a bad question.如果有人能解释为什么他们认为这是一个糟糕的问题,我将不胜感激。

Apparently everything works on an iPhone 5. It does not work on iPhone 6 and up.显然,一切都适用于 iPhone 5。它不适用于 iPhone 6 及更高版本。 Be advised that the iOS is still 10.2, for both the iPhone 5 and iPhone 6 and 7 also have iOS 10.2请注意,iOS 仍然是 10.2,对于 iPhone 5 和 iPhone 6 和 7 也有 iOS 10.2

Since the only difference between working and not working is the device, not ios version, I am now leaning towards it being an UI bug that only occurs at certain sizes.由于工作和不工作之间的唯一区别是设备,而不是 ios 版本,因此我现在倾向于将其视为仅在某些大小时发生的 UI 错误。

One other issue that arises is that my gesturerecognizer also only works on iPhone5 and not 6+出现的另一个问题是我的手势识别器也只适用于 iPhone5 而不是 6+

New info!新信息!

I can fix the problem by commenting the heightForRowAtIndexPath code.我可以通过注释heightForRowAtIndexPath代码来解决这个问题。 This now means that I need some other way to adjust the height of certain cells and that is the current problem.这现在意味着我需要一些其他方法来调整某些单元格的高度,这就是当前的问题。 I still have no idea at all why uitableview behaves this way.我仍然完全不知道为什么 uitableview 会这样。

The reason for this particular problem was that the method "heightForRowAtIndexPath" returns a double on iPhone 5 and long on iPhone 6, to be correct, one should use a defined datatype called "CGFloat"!这个特殊问题的原因是方法“heightForRowAtIndexPath”在 iPhone 5 上返回一个双精度值,在 iPhone 6 上返回一个长整数,正确地说,应该使用一个名为“CGFloat”的定义数据类型!

It was not easy to find this problem and I hope I can help someone else with this.找到这个问题并不容易,我希望我可以帮助其他人。 Also thanks to anyone that tried to help!也感谢任何试图提供帮助的人!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM