ngViewController9tableViewfTCSo1

ngViewController9tableViewfTCSo1

本文介绍了由于未捕获的异常“NSRangeException"而终止应用程序,原因:“*** -[__NSArray0 objectAtIndex:]:索引 2 超出空 NSArray 的界限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

日志错误:

* 由于未捕获的异常NSRangeException"而终止应用,原因:* -[NSArray0 objectAtIndex:]:索引 2 超出空 NSArray 的界限"*** 首先抛出调用堆栈:(0 核心基金会 0x000000010fdd8b0b __exceptionPreprocess + 1711 libobjc.A.dylib 0x00000001143a6141 objc_exception_throw + 482 核心基金会 0x000000010fdf027d -[__NSArray0 objectAtIndex:] + 933 DropInn 0x000000010d598fc4 _TFC7DropInn21ListingViewController9tableViewfTCSo11UITableView14didSelectRowAtV10Foundation9IndexPath_T_ + 59724 DropInn 0x000000010d599837 _TToFC7DropInn21ListingViewController9tableViewfTCSo11UITableView14didSelectRowAtV10Foundation9IndexPath_T_ + 875 UIKit 0x00000001122b3dcd -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 17636 UIKit 0x00000001122b3fe3 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 3447 UIKit 0x00000001121697f3 _runAfterCACommitDeferredBlocks + 3188 UIKit 0x00000001121567bc _cleanUpAfterCAFlushAndRunDeferredBlocks + 5329 UIKit 0x000000011218828c _afterCACommitHandler + 13710 核心基金会 0x000000010fd7e717 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 2311 核心基金会 0x000000010fd7e687 __CFRunLoopDoObservers + 39112 核心基金会 0x000000010fd63720 __CFRunLoopRun + 120013 核心基金会 0x000000010fd63016 CFRunLoopRunSpecific + 40614 图形服务 0x0000000118249a24 GSEventRunModal + 6215 UIKit 0x000000011215d0d4 UIApplicationMain + 15916 DropInn 0x000000010d240f47 主 + 5517 libdyld.dylib 0x0000000115fba65d 开始 + 1)libc++abi.dylib:以未捕获的 NSException 类型异常终止

错误截图:

源代码:

let savearr : NSArray = (UserDefaults.standard.object(forKey: "savedarray") as! NSArray)

print("Savearr data ->", savearr)

let addarr: NSArray = savearr.value(forKeyPath:"country") as! NSArray
let sumarr: NSArray = savearr.value(forKeyPath:"description") as! NSArray
let titarr: NSArray = savearr.value(forKeyPath:"title") as! NSArray

appDelegate.indexrow = indexPath.row

print("addarr\(addarr)")
print("sumarr\(sumarr)")
print("titarr\(titarr)")

let MenuViewController = self.storyboard?.instantiateViewController(withIdentifier: "five") as! FiveStepsViewController

MenuViewController.writeTitleString = String(describing: titarr[indexPath.row])

MenuViewController.writeSummaryString = String(describing: sumarr[indexPath.row])

MenuViewController.writeAddressString = String(describing: addarr[indexPath.row])

//MenuViewController.writePriceString = String(describing: self.appDelegate.fivepricearray[indexPath.row])

self.present(MenuViewController, animated: true, completion: nil)

错误显示在:

MenuViewController.writeTitleString = String(describing: titarr[indexPath.row])

MenuViewController.writeSummaryString = String(describing: sumarr[indexPath.row])

MenuViewController.writeAddressString = String(describing: addarr[indexPath.row])

推荐答案

if ( titarr.count > 0 ) {
   // rest of your code
}

这篇关于由于未捕获的异常“NSRangeException"而终止应用程序,原因:“*** -[__NSArray0 objectAtIndex:]:索引 2 超出空 NSArray 的界限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 11:45