![ios – ‘*** – [__ NSArrayM insertObject:atIndex:]:执行UITableView动画重新加载时,对象不能为nil,第1张 ios – ‘*** – [__ NSArrayM insertObject:atIndex:]:执行UITableView动画重新加载时,对象不能为nil,第1张](/aiimages/ios+%E2%80%93+%E2%80%98%2A%2A%2A+%E2%80%93+%5B__+NSArrayM+insertObject%EF%BC%9AatIndex%EF%BC%9A%5D%EF%BC%9A%E6%89%A7%E8%A1%8CUITableView%E5%8A%A8%E7%94%BB%E9%87%8D%E6%96%B0%E5%8A%A0%E8%BD%BD%E6%97%B6%2C%E5%AF%B9%E8%B1%A1%E4%B8%8D%E8%83%BD%E4%B8%BAnil.png)
长问题:我已经成功实现,所以我可以动态地使用iOS 8自定义单元格进入单元格UITextVIEw的文本,并改变单元格高度而不失去焦点(firstReponder).但是,如果tableVIEw太大(行数太多),则会崩溃.这是我的堆栈跟踪:
Terminating app due to uncaught exception 'NSinvalidargumentexception',reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'*** First throw call stack:(0 CoreFoundation 0x000000010b3b3d85 __exceptionPreprocess + 1651 libobjc.A.dylib 0x000000010b9cbdeb objc_exception_throw + 482 CoreFoundation 0x000000010b274cc5 -[__NSArrayM insertObject:atIndex:] + 9013 UIKit 0x0000000108b05439 __46-[UItableVIEw _updateWithItems:updateSupport:]_block_invoke1029 + 1804 UIKit 0x0000000108a7e838 +[UIVIEw(UIVIEwAnimationWithBlocks) _setupAnimationWithDuration:delay:vIEw:options:factory:animations:start:animationStateGenerator:completion:] + 5825 UIKit 0x0000000108a7ec6d +[UIVIEw(UIVIEwAnimationWithBlocks) animateWithDuration:delay:options:animations:completion:] + 1056 UIKit 0x0000000108b05048 -[UItableVIEw _updateWithItems:updateSupport:] + 45907 UIKit 0x0000000108afd5a0 -[UItableVIEw _endCellAnimationsWithContext:] + 153608 Test RYM 0x0000000107e6a173 _TFE8Test_RYMCSo11UItableVIEw31reloadDataAnimatedKeePingOffsetfT_T_ + 1639 Test RYM 0x0000000107e6a242 _TToFE8Test_RYMCSo11UItableVIEw31reloadDataAnimatedKeePingOffsetfT_T_ + 3410 Test RYM 0x0000000107dcda90 _TFC8Test_RYM20AgendaVIEwController19cellHeightDIDUpdatefTCSo11NSIndexPath6heightV12CoreGraphics7CGfloat_T_ + 14411 Test RYM 0x0000000107dcdb04 _TToFC8Test_RYM20AgendaVIEwController19cellHeightDIDUpdatefTCSo11NSIndexPath6heightV12CoreGraphics7CGfloat_T_ + 6812 Test RYM 0x0000000107e725cb _TFC8Test_RYM27AgendaDecisiontableVIEwCell20updateTextVIEwHeightfT_T_ + 90713 Test RYM 0x0000000107e731fa _TFC8Test_RYM27AgendaDecisiontableVIEwCell17textVIEwDIDChangefCSo10UITextVIEwT_ + 42
并导致它的代码:
// In UItableVIEw extensionfunc reloadDataAnimatedKeePingOffset() { //let offset = contentOffset //UIVIEw.setAnimationsEnabled(false) beginUpdates() endUpdates() //UIVIEw.setAnimationsEnabled(true) //layoutIfNeeded() //contentOffset = offset}// In a self-sizing UItableVIEwCell subclassfunc updateTextVIEwHeight() { let size = decisionTextVIEw.bounds.size let newSize = decisionTextVIEw.sizeThatFits(CGSize(wIDth: size.wIDth,height: CGfloat.max)) let newHeight = newSize.height if size.height != newHeight { textVIEwHeightConstraint.constant = newHeight agendaVIEwController?.cellHeightDIDUpdate(indexPath!,height: newSize.height) }}// In the VIEwController managing the tableVIEwpublic func cellHeightDIDUpdate(indexPath: NSIndexPath,height: CGfloat) { updateHelperAlphas() tableVIEw?.reloadDataAnimatedKeePingOffset()} 它在调用endUpdates()时崩溃.我已经尝试删除tableVIEw:estimateHeightForRowAtIndexPath:方法在UITableView insertRowsAtIndexPaths throwing __NSArrayM insertObject:atIndex:’object cannot be nil’ error中没有成功.
它似乎只发生在列表很长时间.
编辑:我使用的更多方法:
public func tableVIEw(tableVIEw: UItableVIEw,estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGfloat { return 48.0}public func tableVIEw(tableVIEw: UItableVIEw,heightForheaderInSection section: Int) -> CGfloat { if (section == 0) { return 0 } else { let currentSectionIsEmpty = sectionIsEmpty(section) if ((!isInEditProtocolMode && isProtocolMode) || isPrevIoUsProtocolMode) && currentSectionIsEmpty { return 0 } let subSection = sectionHelper.subSectionForSection(section) let isProtocoltopSection = isProtocolMode && subSection == 0 if (isProtocoltopSection) { return UItableVIEwautomaticDimension } else { return agendaheaderHeight } }}public func tableVIEw(tableVIEw: UItableVIEw,estimatedHeightForheaderInSection section: Int) -> CGfloat { if (section == 0) { return 0 } else { let subSection = sectionHelper.subSectionForSection(section) let isProtocoltopSection = isProtocolMode && subSection == 0 if (isProtocoltopSection) { return protocolAgendaheaderHeight } else { return agendaheaderHeight } }}public overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() tableVIEw.rowHeight = UItableVIEwautomaticDimension} EDIT2:
这几乎是同样的问题. tableView crashes on end up with more than 16 items然而,我无法消除细胞高度的估计,因为这破坏了我的自动调整细胞图的动态高度.
编辑3:
尝试(从下面的评论)使用CATransaction.setdisableActions(_)和setContentOffset(_:动画:)没有任何帮助.这似乎与此无关,除了beginUpdates()和endUpdates()都没有帮助. reloadDataAnimatedKeePingOffset()似乎只被调用一次,没有其他reloadData似乎被调用在同一时间.将估计高度设置为1而不是0也没有帮助.它奇怪地显示零标题而不是高度1.
编辑4:
根据请求,我的numberOrRowsInSection和cellForRowAtIndexPath方法(有点复杂):
public func tableVIEw(tableVIEw: UItableVIEw,numberOfRowsInSection section: Int) -> Int{ let mainSection = sectionHelper.mainSectionForSection(section) let subSection = sectionHelper.subSectionForSection(section) let isheaderSection = subSection <= 0 if isheaderSection { return isProtocolMode ? 0 : cellIDSectionList[0].count } let rowType = sectionHelper.rowTypeForSection(section) let agenda = agendaForSection(section) switch rowType { case .NoteRow: return mainSectionShowingPlaceholderNewNoteCell == mainSection || !agenda.protocolString.isEmpty ? 1 : 0 case .ActionRow: let count = max(0,agenda.actionListCount()) return count case .DecisionRow: var count = agenda.decisions.count ?? 0 count = max(0,count) count = indexPathShowingPlaceholderNewDecisionCell?.section == section ? count+1 : count return count default: return 0 }}public func tableVIEw(tableVIEw: UItableVIEw,cellForRowAtIndexPath indexPath: NSIndexPath) -> UItableVIEwCell{ let row = indexPath.row let section = indexPath.section let cellID = cellIDForIndexPath(indexPath) let cell = tableVIEw.dequeueReusableCellWithIDentifIEr(cellID,forIndexPath: indexPath) let allowEditing = (isInEditProtocolMode || !isProtocolMode) && !isPrevIoUsProtocolMode if let TitleCell = cell as? StandardTitletableVIEwCell { TitleCell.setup(agendaForSection(section),meeting:selectedMeeting!,indexPath:indexPath) TitleCell.delegate = self } if let descriptionCell = cell as? StandardDescriptiontableVIEwCell { descriptionCell.setup(agendaForSection(section),indexPath: indexPath,forceExpand: hasExpandedDescriptionCellVIEw) descriptionCell.delegate = self } if let noteCell = cell as? AgendaNotestableVIEwCell { noteCell.setup(agendaForSection(section),allowEditing:allowEditing) noteCell.agendaVIEwController = self } if let decisionCell = cell as? AgendaDecisiontableVIEwCell { let decisionList = agendaForSection(section).decisions let isNewDecisionCell = row >= decisionList.count if !isNewDecisionCell { let decision = decisionList[row] decisionCell.setup(decision,allowEditing: allowEditing) } else { decisionCell.setup(newDecisionToAdd!,allowEditing: allowEditing) } decisionCell.agendaVIEwController = self } if let actionCell = cell as? StandardtableVIEwCell,let actionList = agendaForSection(section).actionList { let action = actionList.actions[row] actionCell.setupAsActionListCell(action:action,delegate: self) } if let textCell = cell as? MeetingTexttableVIEwCell { var placeholderText = "" if indexPathIsActionTextPlaceholderCell(indexPath) { placeholderText = __("agenda.noActions.text") } else if indexPathIsDecisionTextPlaceholderCell(indexPath) { placeholderText = __("agenda.noDecisions.text") } textCell.setup(placeholderText) } return cell}public func tableVIEw(tableVIEw: UItableVIEw,vIEwForheaderInSection section: Int) -> UIVIEw?{ if (section == 0) { return nil } let subSection = sectionHelper.subSectionForSection(section) let cellID = isProtocolMode && subSection == 0 ? protocolheaderCellID : headerCellID let cell = tableVIEw.dequeueReusableheaderfooterVIEwWithIDentifIEr(cellID) let agenda = agendaForSection(section) if let standardheaderCell = cell as? StandardtableVIEwheaderCell { let subSection = sectionHelper.subSectionForSection(section) let currentSectionIsEmpty = sectionIsEmpty(section) let protocolisLocked = selectedMeeting!.protocolisLocked if (isPrevIoUsProtocolMode && currentSectionIsEmpty) { return nil } let allowEditing = (isInEditProtocolMode || !isProtocolMode) && !isPrevIoUsProtocolMode && !protocolisLocked let showRightAddbutton = ((subSection == 1 && currentSectionIsEmpty) || subSection == 2 || (subSection == 3 && indexPathShowingPlaceholderNewDecisionCell?.section != section)) && allowEditing let headerTitle = headerTitleList[subSection] standardheaderCell.setupWithText(headerTitle,section:section,showAddbutton: showRightAddbutton,delegate: self) } else if let protocolheaderCell = cell as? ProtocoltableVIEwheaderCell { let showSeparator = section > 1 let onlyShowAttachmentIfItHaveAttachments = isPrevIoUsProtocolMode || (isProtocolMode && !isInEditProtocolMode) let showAttachmentIcon = !onlyShowAttachmentIfItHaveAttachments || agenda.attachments.count > 0 protocolheaderCell.setup(showSeparator: showSeparator,agenda: agenda,section: section,showProtocolicon: false,showAttachmentIcon: showAttachmentIcon,delegate: self) } return cell!.wrappedInNewVIEw()}// In UIVIEw extensionfunc wrappedInNewVIEw() -> UIVIEw{ let vIEw = UIVIEw(frame: frame) autoresizingMask = [.FlexibleHeight,.FlexibleWIDth] vIEw.addSubvIEw(self) return vIEw}解决方法 这是关于这个iOS BUG的雷达: http://openradar.appspot.com/15729686 所有我建议你要做的是取代这个:
public func tableVIEw(tableVIEw: UItableVIEw,estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGfloat { return 48.0} 有了这个:
tableVIEw.rowHeight = UItableVIEwautomaticDimensiontableVIEw.estimatedRowHeight = 48.0
如果还是崩溃了,那么也尝试去除tableVIEw:estimatedHeightForheaderInSection:方法
我们应该穿过我们的手指,希望这个雷达将关闭与新的iOS X 总结
以上是内存溢出为你收集整理的ios – ‘*** – [__ NSArrayM insertObject:atIndex:]:执行UITableView动画重新加载时,对象不能为nil全部内容,希望文章能够帮你解决ios – ‘*** – [__ NSArrayM insertObject:atIndex:]:执行UITableView动画重新加载时,对象不能为nil所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)