gpt4 book ai didi

iphone - 有时在调用 reloadData 时调用 numberOfRowsInSection 后不会调用 cellForRowAtIndexPath

转载 作者:行者123 更新时间:2023-12-03 18:50:52 25 4
gpt4 key购买 nike

我有一个简单的应用程序,其中有一个 TableView ,并且根据数组的回调,我使用 reloadData 方法重新加载表数据。最初加载此 TableView 的前 5-10 次没有任何问题。有时在使用该应用程序后,我注意到表格 View 是空白的,因为框架没有调用 cellForRowAtIndexPath 。我验证了 datasourcedelegate 设置正确,并且 numberOfRowsInSection 返回有效的正数。一旦我看到空白表格 View ,我就可以重复看到这个空白 View ,直到退出应用程序。我在控制台中没有收到任何错误或警告。我尝试调整数组但无济于事。

这是代码:

- (void)notifyArrayLoaded:(NSArray *)arr {
NSUInteger capacity = [arr count];
_tbDataArray = [[NSMutableArray alloc] initWithCapacity:capacity];

// _tbDataArray is filled with the data from arr

// Reload the table data
[_tableView reloadData];
}

任何线索都将受到高度赞赏。

提前致谢。苏米特

嗨 DeanWombourne,我没有 viewDidUnLoad 方法,但我有 viewWillDisAppear 方法,我将其发布在这里。

- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationPortrait;
[[UIApplication sharedApplication] setStatusBarHidden:NO animated:NO];
[self.navigationController setNavigationBarHidden:NO animated:NO];

UIWindow *window = [[UIApplication sharedApplication] keyWindow];
UIView *view = [window.subviews objectAtIndex:0];

view.transform = CGAffineTransformIdentity;
view.transform = CGAffineTransformMakeRotation(0);
view.bounds = CGRectMake(0.0, 0.0, 320, 480);
}

这是 tableView 记录的日志。

[numberOfSectionsInTableView:] [Line 223] <UITableView: 0xa5fc00; frame = (0 0; 320 0); clipsToBounds = YES; layer = <CALayer: 0x4830b0>; contentOffset: {0, 0}>
[tableView:numberOfRowsInSection:] [Line 229] <UITableView: 0xa5fc00; frame = (0 0; 320 0); clipsToBounds = YES; layer = <CALayer: 0x4830b0>; contentOffset: {0, 0}>
<UITableView: 0xa5fc00; frame = (0 0; 320 0); clipsToBounds = YES; layer = <CALayer: 0x4830b0>; contentOffset: {0, 0}>
[numberOfSectionsInTableView:] [Line 223] <UITableView: 0xa5fc00; frame = (0 0; 320 0); clipsToBounds = YES; layer = <CALayer: 0x4830b0>; contentOffset: {0, 0}>
[tableView:numberOfRowsInSection:] [Line 229] <UITableView: 0xa5fc00; frame = (0 0; 320 0); clipsToBounds = YES; layer = <CALayer: 0x4830b0>; contentOffset: {0, 0}>

最佳答案

确保在主线程上调用 reloadData。如果您使用 performSelectorInBackground 异步加载数据并在该方法中调用 reloadData,您应该这样做,而不是执行以下操作:

[tableViewController reloadData]

你应该做的是

[tableViewController performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO]

关于iphone - 有时在调用 reloadData 时调用 numberOfRowsInSection 后不会调用 cellForRowAtIndexPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5894980/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com