2015-08-31 10 views
9

एक्सकोड 7 बीटा 6 और एनएसफ़ेटेड रीसेट कंट्रोलर ने मुझे आज सिरदर्द दिया। यदि मैं एक्सकोड 6 के साथ कोड (स्विफ्ट 2 फिक्स के साथ) संकलित करता हूं, तो प्रोग्राम डिवाइस और सिमुलेटर (आईओएस 7, आईओएस 8) पर काम करता है। हालांकि अगर मैं एक्सकोड 7 बीटा 6 के साथ संकलित करता हूं, तो जब भी मैं कोर डेटा अपडेट करता हूं, तो निम्न त्रुटि संदेशों के साथ डिवाइस (आईओएस 8.4) पर प्रोग्राम क्रैश हो जाता है।NSFetchedResultsController XCode 7 अंक

मैं करने के लिए

CoreData: error: Serious application error. An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:. Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (2) must be equal to the number of rows contained in that section before the update (2), plus or minus the number of rows inserted or deleted from that section (2 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out). with userInfo (null)

नीचे कभी कभी यह .Update अनुभाग के लिए

Invalid pointer dequeued from free list *** set a breakpoint in malloc_error_break to debug

//NSFetchedResultsController delegates 



func controllerWillChangeContent(controller: NSFetchedResultsController) { 
    self.tableView.beginUpdates() 
} 

func controller(controller: NSFetchedResultsController, didChangeSection sectionInfo: NSFetchedResultsSectionInfo, atIndex sectionIndex: Int, forChangeType type: NSFetchedResultsChangeType) { 
    switch type { 
    case .Insert: 
     self.tableView.insertSections(NSIndexSet(index: sectionIndex), withRowAnimation: .Fade) 
    case .Delete: 
     self.tableView.deleteSections(NSIndexSet(index: sectionIndex), withRowAnimation: .Fade) 
    default: 
     return 
    } 
} 

func controller(controller: NSFetchedResultsController, didChangeObject anObject: AnyObject, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath?) { 
    switch type { 
    case .Insert: 
     print("Insert New: \(newIndexPath) Old: \(indexPath)") 
     tableView.insertRowsAtIndexPaths([newIndexPath!], withRowAnimation: .Fade) 
    case .Delete: 
     print("Delete New: \(newIndexPath) Old: \(indexPath)") 
     tableView.deleteRowsAtIndexPaths([indexPath!], withRowAnimation: .Fade) 
    case .Update: 
     print("Update New: \(newIndexPath) Old: \(indexPath)") 
     tableView.reloadRowsAtIndexPaths([indexPath!], withRowAnimation: .Fade) 
     //self.configureCell(tableView.cellForRowAtIndexPath(indexPath!)!, atIndexPath: indexPath!) 
    case .Move: 
     print("Move New: \(newIndexPath) Old: \(indexPath)") 
     tableView.deleteRowsAtIndexPaths([indexPath!], withRowAnimation: .Fade) 
     tableView.insertRowsAtIndexPaths([newIndexPath!], withRowAnimation: .Fade) 
    } 
} 

func controllerDidChangeContent(controller: NSFetchedResultsController) { 
    self.tableView.endUpdates() 
} 

की तरह एक और त्रुटि के साथ दुर्घटनाओं समान कोई त्रुटि मिलती है मैं भी

self.configureCell(tableView.cellForRowAtIndexPath(indexPath!)!, atIndexPath: indexPath!) 
कॉल करने की कोशिश

कॉन्फ़िगर सेल विधि:

func configureCell(cell: UITableViewCell, atIndexPath indexPath: NSIndexPath) { 
    let object = self.fetchedResultsController.objectAtIndexPath(indexPath) as! Person 
    //etc 
} 

क्रमबद्ध वर्णनकर्ता

let sortDescriptor = NSSortDescriptor(key: "date", ascending: false) 
fetchRequest.sortDescriptors = [sortDescriptor] 

कार्यक्रम हमेशा दुर्घटनाओं। इस मुद्दे को किसी भी तरह से रोकने का एकमात्र तरीका नील को अद्यतन करना, ऑब्जेक्ट अपडेट करना और स्वयं को वापस भेजना सेट करना है।

क्या यह एक बग है? यदि यह नहीं है, तो मैं इसे कैसे रोक सकता हूं? धन्यवाद

ही/समान मुद्दे के साथ कुछ बग रिपोर्ट

https://forums.developer.apple.com/thread/12184

https://forums.developer.apple.com/thread/4999

iOS 9 - "attempt to delete and reload the same index path"

मैं दोनों XCode6 और XCode7 संस्करणों भाग गया और didChangeObject विधि यहाँ मुद्रित तुलना

है

XCode6 आईओएस 8,4

Update New: Optional(<NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}) Old: Optional(<NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}) 

XCode 7b6 आईओएस 8,4

Update New: nil Old: Optional(<NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}) 
Insert New: Optional(<NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}) Old: Optional(<NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}) 

2015-09-01 01:15:37.898 TestProg[3230:200562] *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit/UIKit-3347.44.2/UITableView.m:1623 
2015-09-01 01:15:37.900 TestProg[3230:200562] CoreData: error: Serious application error. An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:. Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (3) must be equal to the number of rows contained in that section before the update (3), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out). with userInfo (null) 
+0

मेरी वर्तमान प्रोजेक्ट में मैं 'कॉन्फ़िगरेशन' विधि का भी उपयोग करता हूं, मुझे लगता है कि मैंने इसे एक समान बग के कारण बदल दिया है। क्या आप शायद अपनी कॉन्फ़िगर सेल विधि दिखा सकते हैं? – Mundi

+0

यह सबसे बॉयलरप्लेट कोड है। मेरे पास कई रिश्ते हैं। नीचे कुछ ऐसा है: func configCell (सेल: UITableViewCell, atIndexPath indexPath: NSIndexPath) { ऑब्जेक्ट = self.fetchedResultsController.objectAtIndexPath (indexPath) के रूप में दें! व्यक्ति // आदि } – Meanteacher

+0

क्या आपके एफआरसी में एक प्रकार का वर्णनकर्ता है या एक प्रमुख मार्ग के माध्यम से रिश्ते का जिक्र करने वाला भविष्य है? यह कभी-कभी अप्रत्याशित परिणामों का कारण बन सकता है। – Mundi

उत्तर

10

मैंने कई चीजों की कोशिश की है और मुझे विश्वास है कि यह एक बग है। जैसा कि आप मेरे लॉग से देख सकते हैं, भले ही मैं मौजूदा रिकॉर्ड अपडेट करता हूं, प्रतिनिधि को संदेश सम्मिलित किया जाता है। .Insert पर सशर्त चेक जोड़ने से मेरी समस्या ठीक हो गई। मैं तालिका में किसी भी कदम संचालन का उपयोग नहीं कर रहा हूँ।सशर्त आपरेशन शायद आवश्यक का इसलिए एक ही प्रकार के रूप में अच्छी तरह से आप .Move मेरे वर्तमान कोड प्रयोग कर रहे हैं की तरह

नीचे
func controller(controller: NSFetchedResultsController, didChangeObject anObject: AnyObject, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath?) { 
    switch type { 
    case .Insert: 
     //FIXME: iOS 9 Bug! 
     if indexPath != newIndexPath { 
      tableView.insertRowsAtIndexPaths([newIndexPath!], withRowAnimation: .Fade) 
     } 
    case .Delete: 
     tableView.deleteRowsAtIndexPaths([indexPath!], withRowAnimation: .Fade) 
    case .Update: 
     tableView.reloadRowsAtIndexPaths([indexPath!], withRowAnimation: .Fade) 
     // self.configureCell(tableView.cellForRowAtIndexPath(indexPath!)!, atIndexPath: indexPath!) 

    case .Move: 
     tableView.deleteRowsAtIndexPaths([indexPath!], withRowAnimation: .Fade) 
     tableView.insertRowsAtIndexPaths([newIndexPath!], withRowAnimation: .Fade) 
    } 
} 

मैं एक रिकॉर्ड, कई रिकॉर्ड को अपडेट करने की कोशिश की है और मैं किसी भी दुर्घटनाओं अभी तक अब तक नहीं देखा है है। मैं

tableView.reloadRowsAtIndexPaths([indexPath!], withRowAnimation: .Fade) 

विधि लेकिन

self.configureCell(tableView.cellForRowAtIndexPath(indexPath!)!, atIndexPath: indexPath!) 

भी मेरी परीक्षण के दौरान काम किया उपयोग कर रहा हूँ।

+0

यह भी मेरे लिए काम कर रहा है। – Chinthaka

+0

क्या आपको पता है कि यह एक्सकोड 7.1 बीटा 2 के साथ काम करता है? –

+0

मैंने केवल एक्सकोड 7.0 बीटा 6, जीएम, और एक्सकोड 7.0 रिलीज बिल्ड के साथ परीक्षण किया। – Meanteacher

1

यह मैं के लिए हो रहा है जब सिम/डिवाइस < iOS9 का उपयोग कर Xcode 7 बीटा 6 पर चल रहा है लगता है:

2015-09-01 11:39:05.683 Diabetes Pal[15038:245613] *** Assertion failure in 
-[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-3347.44.2/UITableView.m:1623 
2015-09-01 11:39:14.954 Diabetes Pal[15038:245613] CoreData: error: Serious application error. 
An exception was caught from the delegate of NSFetchedResultsController during a call to 
-controllerDidChangeContent:. Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (4) must be equal to the number of rows contained in that section before the update (4), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out). with userInfo (null) 
Diabetes Pal(15038,0x33291d4) malloc: *** mach_vm_map(size=1048576) failed (error code=3) 
*** error: can't allocate region securely 
*** set a breakpoint in malloc_error_break to debug 

एक संभावित कामकाज परिवर्तन को एनिमेट नहीं करना है (जब तक यह तय नहीं हो जाता है):

//MARK: - fetched results controller delegate 

func controllerWillChangeContent(controller: NSFetchedResultsController) { 
    let ios9 = NSOperatingSystemVersion(majorVersion: 9, minorVersion: 0, patchVersion: 0) 
    if NSProcessInfo().isOperatingSystemAtLeastVersion(ios9) { 
     tableView?.beginUpdates() 
    } 
} 

func controller(controller: NSFetchedResultsController, didChangeSection sectionInfo: NSFetchedResultsSectionInfo, atIndex sectionIndex: Int, forChangeType type: NSFetchedResultsChangeType) {   
    let ios9 = NSOperatingSystemVersion(majorVersion: 9, minorVersion: 0, patchVersion: 0) 
    if NSProcessInfo().isOperatingSystemAtLeastVersion(ios9) == false { 
     return 
    } //[... rest of delegate implementation ...] 
} 

func controller(controller: NSFetchedResultsController, didChangeObject anObject: AnyObject, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath?) { 

    let ios9 = NSOperatingSystemVersion(majorVersion: 9, minorVersion: 0, patchVersion: 0) 
    if NSProcessInfo().isOperatingSystemAtLeastVersion(ios9) == false { 
     return 
    }//[... rest of delegate implementation ...] 
} 

func controllerDidChangeContent(controller: NSFetchedResultsController) { 
    let ios9 = NSOperatingSystemVersion(majorVersion: 9, minorVersion: 0, patchVersion: 0) 
    if NSProcessInfo().isOperatingSystemAtLeastVersion(ios9) == false { 
     tableView?.reloadData() 
     return 
    } 
    tableView?.endUpdates() 
} 
+0

इस मुद्दे को हल किया। – Chinthaka

0

जब मैं एसडीके 9.1 पर निर्माण करता हूं तो मुझे यह समस्या और नहीं दिखाई देती थी। ऐसा लगता है कि बग तय किया गया है। आप इसे आज़मा सकते हैं।

+0

मेरे लिए तय नहीं है –

संबंधित मुद्दे