我想在完成表演后滚动到UITableView的底部 [self.tableView reloadData]
我原本有
[self.tableView reloadData]
NSIndexPath* indexPath = [NSIndexPath indexPathForRow: ([self.tableView numberOfRowsInSection:([self.tableView numberOfSections]-1)]-1) inSection: ([self.tableView numberOfSections]-1)];
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
Run Code Online (Sandbox Code Playgroud)
但后来我读了reloadData是异步的,所以滚动不因为发生self.tableView,[self.tableView numberOfSections]并且[self.tableView numberOfRowsinSection都是0.
谢谢!
有什么奇怪的是我正在使用:
[self.tableView reloadData];
NSLog(@"Number of Sections %d", [self.tableView numberOfSections]);
NSLog(@"Number of Rows %d", [self.tableView numberOfRowsInSection:([self.tableView numberOfSections]-1)]-1);
Run Code Online (Sandbox Code Playgroud)
在控制台中它返回Sections = 1,Row = -1;
当我完成相同的NSLogs时,cellForRowAtIndexPath我得到Sections = 1和Row = 8; (8是对的)
我想在加载完成后更改表的偏移量,并且该偏移量取决于表上加载的单元格数.
是否可以通过SDK知道uitableview加载何时完成?我在委托和数据源协议上都没有看到任何内容.
我不能使用数据源的计数,因为只加载可见单元格.
我有一个tableView,我在顶部插入行.
虽然我这样做,但我希望当前视图保持完全静止,因此只有向上滚动时才会显示行.
我已经尝试保存底层UIScrollview的当前位置并在插入行之后重置位置,但这导致抖动,上下,尽管它最终返回到同一位置.
有没有一个很好的方法来实现这一目标?
更新:我使用的是beginUpdate,然后是insertRowsAtIndexPath,endUpdates.没有reloadData调用.
scrollToRowAtIndexPath跳转到当前单元格的顶部(在添加行之前保存).
我试过的另一种方法,最终以正确的速度结束,但有一个颤抖的是.
save tableView currentOffset. (Underlying scrollView method)
Add rows (beginUpdates,insert...,endUpdates)
reloadData ( to force a recalulation of the scrollview size )
Recalculate the correct new offset from the bottom of the scrollview
setContentOffset (Underlying scrollview method)
Run Code Online (Sandbox Code Playgroud)
麻烦是reloadData导致scrollview/tableview开始短暂滚动,然后setContentOffset将它返回到正确的位置.
有没有办法让tableView在没有开始显示的情况下计算出它的新尺寸?
将整个事物包装在beginAnimation commitAnimation中也没有多大帮助.
更新2:这显然可以完成 - 当您下载更新时,请参阅官方Twitter应用程序.
我通常使用viewDidAppear方法在视图完成后出现在视图上做一些UI的东西,我在各种情况下使用这个方法是非常有用的,但是,我需要UITableViewCell在完成出现之后做一些UI更改,是否有任何可用的SDK中执行类似工作的方法,viewDidAppear但是对于UITableViewCell?
ps willDisplayCell在我的情况下不起作用,我需要像didDisplayCell它真的存在的东西.
我在使用ios 7的UICollectionView中遇到了一个奇怪的崩溃,这种情况在滚动非常快时往往会发生.此处有关Apple Developer Forms的类似问题:https://devforums.apple.com/message/901009#901009
我想知道是否有人经历过这个并找到了修复/解决方法?
我正在使用配置了流布局的基本UICollection视图.它是通过网络从json数据填充的.数据会定期更改.当它reloadData被调用时,该方法被调用.我已经检查过以确保在主线程上总是调用reload方法,因为我担心我的一个网络回调是在后台线程上回调.绝对不是这样的.
打开NSZmobies时,崩溃发生时会收到以下日志消息:
*** -[NSIndexPath section]: message sent to deallocated instance 0x218b74c0
Run Code Online (Sandbox Code Playgroud)
我还使用Zombies跟踪模板运行我的应用程序附加到仪器,并能够获得以下堆栈跟踪详细说明导致崩溃的调用序列.
请注意, 所有调用都是iOS框架级调用,而不是我的应用程序调用.
0 libsystem_malloc.dylib malloc_zone_calloc
1 libsystem_malloc.dylib calloc
2 libobjc.A.dylib class_createInstance
3 libobjc.A.dylib +[NSObject allocWithZone:]
4 Foundation +[NSIndexPath indexPathWithIndexes:length:]
5 UIKit +[NSIndexPath(UITableView) indexPathForRow:inSection:]
6 UIKit -[UICollectionViewFlowLayout _layoutAttributesForItemsInRect:]
7 UIKit -[UICollectionViewFlowLayout layoutAttributesForElementsInRect:]
8 UIKit __45-[UICollectionViewData validateLayoutInRect:]_block_invoke
9 UIKit -[UICollectionViewData validateLayoutInRect:]
10 UIKit -[UICollectionView layoutSubviews]
11 UIKit -[UIView(CALayerDelegate) layoutSublayersOfLayer:]
12 QuartzCore -[CALayer layoutSublayers]
13 QuartzCore CA::Layer::layout_if_needed(CA::Transaction*)
14 QuartzCore CA::Layer::layout_and_display_if_needed(CA::Transaction*) …Run Code Online (Sandbox Code Playgroud) 我的表视图涵盖了视图的一部分.如果我有20个对象,我将在tableview中显示所有这些对象.但我想知道用户可以看到加载了多少个单元格.(即前5个单元格数据对我来说是可见的:当我向下滚动时,剩余的单元格将会加载.这里我想知道如何不滚动加载了多少个单元格.)
这可能吗?
uitableview ×5
objective-c ×4
ios ×3
iphone ×3
uikit ×2
crash ×1
reloaddata ×1
uiscrollview ×1
xcode ×1