Assertion failure in -[UICollectionViewData validateLayoutInRect:],

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Baby_come_here/article/details/53101320

UICollection 报错

 Assertion failure in -[UICollectionViewData validateLayoutInRect:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.30.14/UICollectionViewData.m:399
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UICollectionView received layout attributes for a cell with an index path that does not exist: <NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}'

描述一下场景:

我使用collectionView 创建了一个瀑布流效果, 并且缓存了数据. 当我进入这个界面时, 我会先加载缓存数据, 再加载网络数据. 我怀疑报这个错误的原因是: 我加载网络数据后. [collection reloaddata] . 但是这时候 layout 可能没有更新

解决办法:

在网络上找了一些资料

-(NSInteger )numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    [collectionView.collectionViewLayout invalidateLayout];
    return 1;
}

参考资料

http://stackoverflow.com/questions/18339030/uicollectionview-assertion-error-on-stale-data

It depends on whether your layout changes too. If your data change is just appending to the end, then you will not need to - if data is inserted above/within your current scroll position, then your cells for those index paths will move, and hence the layout is invalid

UpdateData导致的Assertion Failure~~

03-10

界面上有三个Edit控件,分别控制R,G,B值,用如下函数确定颜色:rnvoid CCComboDlgDlg::OnChangeEdit() rnrn // TODO: If this is a RICHEDIT control, the control will notrn // send this notification unless you override the CDialog::OnInitDialog()rn // function and call CRichEditCtrl().SetEventMask()rn // with the ENM_CHANGE flag ORed into the mask.rn rn // TODO: Add your control notification handler code herernrn UpdateData();rn m_ForeColor=RGB(m_Rvalue,m_Gvalue,m_Bvalue);rn Draw();rnrn=====================rn想通过UpdateData()从Edit控件得到R,G,B值到m_Rvalue,m_Gvalue,m_Bvalue,但是执行到这里总会Assertion Failure,rnvoid AFXAPI DDX_Control(CDataExchange* pDX, int nIDC, CWnd& rControl)rnrn if (rControl.m_hWnd == NULL) // not subclassed yetrn rn ASSERT(!pDX->m_bSaveAndValidate); //=============这里出错rnrn 省略若干.......rnrn rnrn==================rn我的DoDataExchange内容如下:rnvoid CCComboDlgDlg::DoDataExchange(CDataExchange* pDX)rnrn CDialog::DoDataExchange(pDX);rn //AFX_DATA_MAP(CCComboDlgDlg)rn DDX_Control(pDX, IDC_SPIN3, m_Bspin);rn DDX_Control(pDX, IDC_SPIN2, m_Gspin);rn DDX_Control(pDX, IDC_SPIN1, m_Rspin);rn DDX_Control(pDX, IDC_PATTERN, m_PatCom);rn DDX_Text(pDX, IDC_EDIT1, m_Rvalue);rn DDV_MinMaxInt(pDX, m_Rvalue, 0, 255);rn DDX_Text(pDX, IDC_EDIT2, m_Gvalue);rn DDV_MinMaxInt(pDX, m_Gvalue, 0, 255);rn DDX_Text(pDX, IDC_EDIT3, m_Bvalue);rn DDV_MinMaxInt(pDX, m_Bvalue, 0, 255);rn DDX_CBString(pDX, IDC_PATTERN, m_Pattern);rn //AFX_DATA_MAPrnrn==============================rn急盼解决~望各位达人鼎力相助~:)

Assertion failure with my program

09-01

小弟,写了一个主要进行控件测试的简单例子,但在加入ListBox进行测试后缺出现了rnDebug Assertion Failed!rnPrgrame:G:\C++\Newcontrol\Debug\NewControl.exernFile: afxcmn.inlrnLine: 186rnrn我的版本是VC6.0rnrnrn通过在网上的搜索,我感觉可能是List没有进行初始化,但我又不知道是不是这个原因,而且也不知道具体怎么进行初始化。rnrnrnrn关于List控件的代码如下rnControlDialog.cpprn// create two image list control objectrn m_SmallImgList.Create(16,16, ILC_COLOR, 1, 0);rn m_FullImgList.Create(32, 32, ILC_COLOR, 1, 0);rn HICON hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ENVELOP)); rn m_SmallImgList.Add(hIcon);rn hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_BALL));rn m_FullImgList.Add(hIcon);rnrn // create two column to insert to list new controlrn rn LV_COLUMN Column;rn Column.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;rn Column.fmt = LVCFMT_LEFT;rn Column.cx = 60;rn Column.iSubItem = 0;rn Column.pszText = "file";rn m_list.InsertColumn(0, &Column);rn Column.iSubItem = 1;rn Column.pszText = "size";rn m_list.InsertColumn(1, &Column);rnrn // create items to insert to list view controlrn LV_ITEM item1;rn item1.state = 0;rn item1.stateMask = 0;rn item1.iImage = 0;rnrn // insert item 0rn item1.iItem = 0;rn item1.iSubItem = 0;rn item1.pszText = "hello";rn m_list.InsertItem(&item1);rn m_list.SetItemText(0,1,"50K");rnrn // insert item 1rn item1.iItem = 1;rn item1.iSubItem = 0;rn item1.pszText = "music";rn m_list.InsertItem(&item1);rn m_list.SetItemText(1,1,"1,000K");rnrn // insert item 2rn item1.iItem = 2;rn item1.iSubItem = 0;rn item1.pszText = "book";rn m_list.InsertItem(&item1);rn m_list.SetItemText(2,1,"100k");rnrn // attach image list control to list controlrn m_list.SetImageList(&m_SmallImgList, LVSIL_SMALL);rn m_list.SetImageList(&m_FullImgList,LVSIL_NORMAL);rn rnrnrn关于List的几个方法的定义rnvoid CControlDialog::OnSmall() rnrn // TODO: Add your control notification handler code herernrn SetWindowLong(m_list.m_hWnd, GWL_STYLE, WS_VISIBLE|WS_CHILD|WS_BORDER|LVS_SMALLICON|LVS_EDITLABELS);rn rn rnrnrnvoid CControlDialog::OnLarge() rnrn // TODO: Add your control notification handler code herern SetWindowLong(m_list.m_hWnd, GWL_STYLE, WS_VISIBLE|WS_CHILD|WS_BORDER|LVS_ICON|LVS_EDITLABELS);rn rn rnrnrnvoid CControlDialog::OnReport() rnrn // TODO: Add your control notification handler code herern SetWindowLong(m_list.m_hWnd, GWL_STYLE, WS_VISIBLE|WS_CHILD|WS_BORDER|LVS_REPORT|LVS_EDITLABELS);rn rn rnrnrnvoid CControlDialog::OnbLIST() rnrn // TODO: Add your control notification handler code herern SetWindowLong(m_list.m_hWnd, GWL_STYLE, WS_VISIBLE|WS_CHILD|WS_BORDER|LVS_LIST|LVS_EDITLABELS);rn rnrnrnrn谢谢各位大虾了!!rnrn

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试