UICollectionView - 在一个视图上更新动画太多(UICollectionView - too many update animations on one view)
更新:解决了! 请参阅下面的答案以获得解决方案。
我的应用程序在UICollectionView中显示了许多图像。 当新项目插入太快而集合视图无法处理时,我目前遇到insertItemsAtIndexPaths问题。 以下是例外情况:
NSInternalInconsistencyException原因:在一个视图上更新动画太多 - 一次飞行限制为31
事实证明这是由于我的模型缓冲了多达20个新图像并立即将它们推送到数据源但不在集合视图批量更新块中。 没有批量更新不是由于我的懒惰造成的,而是因为我的数据源之间的抽象层实际上是一个.Net Observable集合(下面的代码)。
我想知道的是开发人员如何防止在飞行中达到31个动画的硬编码限制? 我的意思是当它发生时,你是敬酒。 那么Apple的想法是什么?
Monotouch开发人员阅读代码的注意事项:
崩溃实际上是由UICollectionViewDataSourceFlatReadOnly压倒UIDataBoundCollectionView并使用CollectionChanged事件引起的,它代表底层的observable集合代理控件。 这导致collectionview受到非批量InsertItems调用的打击。 (是保罗,它是一个ReactiveCollection)。
UIDataBoundCollectionView
/// <summary> /// UITableView subclass that supports automatic updating in response /// to DataSource changes if the DataSource supports INotifiyCollectionChanged /// </summary> [Register("UIDataBoundCollectionView")] public class UIDataBoundCollectionView : UICollectionView, IEnableLogger { public override NSObject WeakDataSource { get { return base.WeakDataSource; } set { var ncc = base.WeakDataSource as INotifyCollectionChanged; if(ncc != null) { ncc.CollectionChanged -= OnDataSourceCollectionChanged; } base.WeakDataSource = value; ncc = base.WeakDataSource as INotifyCollectionChanged; if(ncc != null) { ncc.CollectionChanged += OnDataSourceCollectionChanged; } } } void OnDataSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { NSIndexPath[] indexPaths; switch(e.Action) { case NotifyCollectionChangedAction.Add: indexPaths = IndexPathHelper.FromRange(e.NewStartingIndex, e.NewItems.Count); InsertItems(indexPaths); break; case NotifyCollectionChangedAction.Remove: indexPaths = IndexPathHelper.FromRange(e.OldStartingIndex, e.OldItems.Count); DeleteItems(indexPaths); break; case NotifyCollectionChangedAction.Replace: case NotifyCollectionChangedAction.Move: PerformBatchUpdates(() => { for(int i=0; i<e.OldItems.Count; i++) MoveItem(NSIndexPath.FromItemSection(e.OldStartingIndex + i, 0), NSIndexPath.FromItemSection(e.NewStartingIndex + i, 0)); }, null); break; case NotifyCollectionChangedAction.Reset: ReloadData(); break; } } }
UICollectionViewDataSourceFlatReadOnly
/// <summary> /// Binds a table to an flat (non-grouped) items collection /// Supports dynamically changing collections through INotifyCollectionChanged /// </summary> public class UICollectionViewDataSourceFlatReadOnly : UICollectionViewDataSource, ICollectionViewDataSource, INotifyCollectionChanged { /// <summary> /// Initializes a new instance of the <see cref="UICollectionViewDataSourceFlat"/> class. /// </summary> /// <param name="table">The table.</param> /// <param name="items">The items.</param> /// <param name="cellProvider">The cell provider</param> public UICollectionViewDataSourceFlatReadOnly(IReadOnlyList<object> items, ICollectionViewCellProvider cellProvider) { this.items = items; this.cellProvider = cellProvider; // wire up proxying collection changes if supported by source var ncc = items as INotifyCollectionChanged; if(ncc != null) { // wire event handler ncc.CollectionChanged += OnItemsChanged; } } #region Properties private IReadOnlyList<object> items; private readonly ICollectionViewCellProvider cellProvider; #endregion #region Overrides of UICollectionViewDataSource public override int NumberOfSections(UICollectionView collectionView) { return 1; } public override int GetItemsCount(UICollectionView collectionView, int section) { return items.Count; } /// <summary> /// Gets the cell. /// </summary> /// <param name="tableView">The table view.</param> /// <param name="indexPath">The index path.</param> /// <returns></returns> public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath) { // reuse or create new cell var cell = (UICollectionViewCell) collectionView.DequeueReusableCell(cellProvider.Identifier, indexPath); // get the associated collection item var item = GetItemAt(indexPath); // update the cell if(item != null) cellProvider.UpdateCell(cell, item, collectionView.GetIndexPathsForSelectedItems().Contains(indexPath)); // done return cell; } #endregion #region Implementation of ICollectionViewDataSource /// <summary> /// Gets the item at. /// </summary> /// <param name="indexPath">The index path.</param> /// <returns></returns> public object GetItemAt(NSIndexPath indexPath) { return items[indexPath.Item]; } public int ItemCount { get { return items.Count; } } #endregion #region INotifyCollectionChanged implementation // UIDataBoundCollectionView will subscribe to this event public event NotifyCollectionChangedEventHandler CollectionChanged; #endregion void OnItemsChanged(object sender, NotifyCollectionChangedEventArgs e) { if(CollectionChanged != null) CollectionChanged(sender, e); } }
Update: Solved! See my answer below for the solution.
My app displays a number of images in a UICollectionView. And I'm currently experiencing a problem with insertItemsAtIndexPaths when new items are getting inserted too fast for the collection view to handle. Below is the exception:
NSInternalInconsistencyException Reason: too many update animations on one view - limit is 31 in flight at a time
Turns out this was caused by my model buffering up to 20 new images and pushing them to the datasource at once but not inside a collection view batch update block. The absence of the batch update is not caused by laziness on my part but because of an abstraction layer between my datasource which is actually a .Net Observable collection (code below).
What I would like to know is how is the developer supposed to prevent hitting the hard coded limit of 31 animations in flight? I mean when it happens, you are toast. So what was Apple thinking?
Note to Monotouch Developers reading the code:
The crash is effectively caused by the UICollectionViewDataSourceFlatReadOnly overwhelming UIDataBoundCollectionView with CollectionChanged events which it proxies to the control on behalf of the underlying observable collection. Which results in the collectionview getting hammered with non-batched InsertItems calls. (yes Paul, its a ReactiveCollection).
UIDataBoundCollectionView
/// <summary> /// UITableView subclass that supports automatic updating in response /// to DataSource changes if the DataSource supports INotifiyCollectionChanged /// </summary> [Register("UIDataBoundCollectionView")] public class UIDataBoundCollectionView : UICollectionView, IEnableLogger { public override NSObject WeakDataSource { get { return base.WeakDataSource; } set { var ncc = base.WeakDataSource as INotifyCollectionChanged; if(ncc != null) { ncc.CollectionChanged -= OnDataSourceCollectionChanged; } base.WeakDataSource = value; ncc = base.WeakDataSource as INotifyCollectionChanged; if(ncc != null) { ncc.CollectionChanged += OnDataSourceCollectionChanged; } } } void OnDataSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { NSIndexPath[] indexPaths; switch(e.Action) { case NotifyCollectionChangedAction.Add: indexPaths = IndexPathHelper.FromRange(e.NewStartingIndex, e.NewItems.Count); InsertItems(indexPaths); break; case NotifyCollectionChangedAction.Remove: indexPaths = IndexPathHelper.FromRange(e.OldStartingIndex, e.OldItems.Count); DeleteItems(indexPaths); break; case NotifyCollectionChangedAction.Replace: case NotifyCollectionChangedAction.Move: PerformBatchUpdates(() => { for(int i=0; i<e.OldItems.Count; i++) MoveItem(NSIndexPath.FromItemSection(e.OldStartingIndex + i, 0), NSIndexPath.FromItemSection(e.NewStartingIndex + i, 0)); }, null); break; case NotifyCollectionChangedAction.Reset: ReloadData(); break; } } }
UICollectionViewDataSourceFlatReadOnly
/// <summary> /// Binds a table to an flat (non-grouped) items collection /// Supports dynamically changing collections through INotifyCollectionChanged /// </summary> public class UICollectionViewDataSourceFlatReadOnly : UICollectionViewDataSource, ICollectionViewDataSource, INotifyCollectionChanged { /// <summary> /// Initializes a new instance of the <see cref="UICollectionViewDataSourceFlat"/> class. /// </summary> /// <param name="table">The table.</param> /// <param name="items">The items.</param> /// <param name="cellProvider">The cell provider</param> public UICollectionViewDataSourceFlatReadOnly(IReadOnlyList<object> items, ICollectionViewCellProvider cellProvider) { this.items = items; this.cellProvider = cellProvider; // wire up proxying collection changes if supported by source var ncc = items as INotifyCollectionChanged; if(ncc != null) { // wire event handler ncc.CollectionChanged += OnItemsChanged; } } #region Properties private IReadOnlyList<object> items; private readonly ICollectionViewCellProvider cellProvider; #endregion #region Overrides of UICollectionViewDataSource public override int NumberOfSections(UICollectionView collectionView) { return 1; } public override int GetItemsCount(UICollectionView collectionView, int section) { return items.Count; } /// <summary> /// Gets the cell. /// </summary> /// <param name="tableView">The table view.</param> /// <param name="indexPath">The index path.</param> /// <returns></returns> public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath) { // reuse or create new cell var cell = (UICollectionViewCell) collectionView.DequeueReusableCell(cellProvider.Identifier, indexPath); // get the associated collection item var item = GetItemAt(indexPath); // update the cell if(item != null) cellProvider.UpdateCell(cell, item, collectionView.GetIndexPathsForSelectedItems().Contains(indexPath)); // done return cell; } #endregion #region Implementation of ICollectionViewDataSource /// <summary> /// Gets the item at. /// </summary> /// <param name="indexPath">The index path.</param> /// <returns></returns> public object GetItemAt(NSIndexPath indexPath) { return items[indexPath.Item]; } public int ItemCount { get { return items.Count; } } #endregion #region INotifyCollectionChanged implementation // UIDataBoundCollectionView will subscribe to this event public event NotifyCollectionChangedEventHandler CollectionChanged; #endregion void OnItemsChanged(object sender, NotifyCollectionChangedEventArgs e) { if(CollectionChanged != null) CollectionChanged(sender, e); } }
原文:https://stackoverflow.com/questions/19046423
最满意答案
我发现了问题。
问题是我使用的绝对网址是'www',即www.mydomain.com,但cookie主机没有'www'。
现在使用相对网址都很好。 谢谢大家:)
我在这里找到了我的解决方案,最后: Symfony,jQuery.ajax()调用,会话变量丢失
I found the problem.
The issue was that I was using absolute urls with 'www' i.e. www.mydomain.com, but the cookie host was without 'www'.
Using relative urls now is all fine. Thanks all :)
I found here my solutions, at the end: Symfony, jQuery.ajax() call, session variables lost
相关问答
更多-
电脑二级考试 是考access 还是VPF[2022-06-08]
access -
经过身份验证的用户从jQuery向rails API发出AJAX请求(Authenticated user making AJAX requests to rails API from jQuery)[2024-02-27]
AJAX请求(XMLHttpRequest)将在同一域的标准HTTP请求中包含相同的标头。 至于从标题中读取cookie,查找会话信息以及授权请求,行为将是相同的。 An AJAX request (XMLHttpRequest) will contain the same headers at a standard HTTP request for the same domain. As far as reading the cookie from the header, looking up the s ... -
根据您的故事,我想猜测您在使用开发设置时会包含“Acme”,但在使用生产设置时则不会。 检查你的AppKernel.php / composer.json I found solution for this problem. Fixed with update PHP from 5.3.3 to 5.4.22 (all Optional recommendations should be OK).
-
symfony 2.4无法在prod环境中获得学说渠道(symfony 2.4 can't get the doctrine channel in prod environment)[2022-04-14]
将doctrine.dbal.logging设置为true以启用生产学说日志记录。 Set doctrine.dbal.logging to true to enable production doctrine logging. -
当用户返回您的站点时,他们会根据记住我cookie中存储的信息自动进行身份验证。 这允许用户访问受保护的资源,就像用户在访问站点时实际进行了身份验证一样 。 ( 来源 ) 因此,在完全验证用户之前,用户不受信任。 这就是为什么在发生AccessDenied异常时将其重定向到登录页面的原因。 在登录控制器操作上,我已设置注释 @Security("not is_authenticated()") 这样我试图只允许匿名用户访问该页面,完全通过身份验证的用户运行良好,但当我将我的网站切换为仅使用remember ...
-
我用这个函数告诉有人登录: public function isAuthenticated() { $securityContext = $this->container->get('security.context'); return $securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED'); } 所以在你的控制器动作中你可以使用 if (isAuthenticated()) { throw $this->create ...
-
我发现了问题。 问题是我使用的绝对网址是'www',即www.mydomain.com,但cookie主机没有'www'。 现在使用相对网址都很好。 谢谢大家:) 我在这里找到了我的解决方案,最后: Symfony,jQuery.ajax()调用,会话变量丢失 I found the problem. The issue was that I was using absolute urls with 'www' i.e. www.mydomain.com, but the cookie host was w ...
-
从ADT 17(IIRC)开始,您会自动将此作为自动生成的BuildConfig类的一部分。 DEBUG字段在开发时始终为true ,但当您导出已签名或未签名的apk时,它将设置为false 。 您可以将其用作: if(BuildConfig.DEBUG) { //Debug mode } 或者相反: if(!BuildConfig.DEBUG) { //Release mode } Starting with ADT 17 (IIRC), you have this automatic ...
-
access_denied_url仅在用户的令牌不是匿名且记住时才有效。 有关更多详细信息,请参阅: https : //github.com/symfony/symfony/blob/2.6/src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php#L120 https://github.com/symfony/symfony /blob/2.6/src/Symfony/Component/Security/Core/Authen ...