- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 objective-c 的新手,我想知道是否有人可以帮助我弄清楚为什么我的应用程序总是崩溃。我相信它与我的阵列有关,但我不确定如何修复它。有人可以帮忙吗??? ..
这是崩溃时的日志输出:
2014-11-26 10:37:42.172 SamplePhotoReDo[89697:109203550] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 2 beyond bounds [0 .. 0]'
*** First throw call stack:
(
0 CoreFoundation 0x000000010c75af35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010c09cbb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010c65301e -[__NSArrayI objectAtIndex:] + 190
3 UIKit 0x000000010d67474a -[UITableViewDataSource tableView:heightForHeaderInSection:] + 39
4 UIKit 0x000000010d221f4e -[UITableView _delegateWantsHeaderForSection:] + 261
5 UIKit 0x000000010d3a6983 -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 162
6 UIKit 0x000000010d3ace45 -[UITableViewRowData rectForFooterInSection:heightCanBeGuessed:] + 320
7 UIKit 0x000000010d3acf3a -[UITableViewRowData heightForTable] + 56
8 UIKit 0x000000010d1ffaf0 -[UITableView _updateContentSize] + 381
9 UIKit 0x000000010d21cecd -[UITableView didMoveToWindow] + 65
10 UIKit 0x000000010d1a39a0 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 1482
11 UIKit 0x000000010d1b4333 -[UIScrollView _didMoveFromWindow:toWindow:] + 55
12 UIKit 0x000000010d1a368e -[UIView(Internal) _didMoveFromWindow:toWindow:] + 696
13 UIKit 0x000000010d19c112 __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 125
14 UIKit 0x000000010d19c086 -[UIView(Hierarchy) _postMovedFromSuperview:] + 437
15 UIKit 0x000000010d1a5f4b -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1604
16 UIKit 0x000000010d486534 -[UINavigationTransitionView transition:fromView:toView:] + 479
17 UIKit 0x000000010d2841ef -[UINavigationController _startTransition:fromViewController:toViewController:] + 2967
18 UIKit 0x000000010d284487 -[UINavigationController _startDeferredTransitionIfNeeded:] + 523
19 UIKit 0x000000010d284f47 -[UINavigationController __viewWillLayoutSubviews] + 43
20 UIKit 0x000000010d3ca509 -[UILayoutContainerView layoutSubviews] + 202
21 UIKit 0x000000010d1a8973 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 521
22 QuartzCore 0x000000011052bde8 -[CALayer layoutSublayers] + 150
23 QuartzCore 0x0000000110520a0e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
24 QuartzCore 0x000000011052087e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
25 QuartzCore 0x000000011048e63e _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
26 QuartzCore 0x000000011048f74a _ZN2CA11Transaction6commitEv + 390
27 UIKit 0x000000010d12d54d -[UIApplication _reportMainSceneUpdateFinished:] + 44
28 UIKit 0x000000010d12e238 -[UIApplication _runWithMainScene:transitionContext:completion:] + 2642
29 UIKit 0x000000010d12cbf2 -[UIApplication workspaceDidEndTransaction:] + 179
30 FrontBoardServices 0x0000000112f002a3 __31-[FBSSerialQueue performAsync:]_block_invoke + 16
31 CoreFoundation 0x000000010c69053c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
32 CoreFoundation 0x000000010c686285 __CFRunLoopDoBlocks + 341
33 CoreFoundation 0x000000010c686045 __CFRunLoopRun + 2389
34 CoreFoundation 0x000000010c685486 CFRunLoopRunSpecific + 470
35 UIKit 0x000000010d12c669 -[UIApplication _run] + 413
36 UIKit 0x000000010d12f420 UIApplicationMain + 1282
37 SamplePhotoReDo 0x000000010bb60453 main + 115
38 libdyld.dylib 0x000000010f2d2145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)'
以下是可能导致崩溃的代码:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1 + self.collectionsFetchResults.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSInteger numberOfRows = 0;
if (section == 0) {
numberOfRows = 1; // "All Photos" section
} else {
PHFetchResult *fetchResult = self.collectionsFetchResults[section - 1];
numberOfRows = fetchResult.count;
}
return numberOfRows;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;
NSString *localizedTitle = nil;
if (indexPath.section == 0) {
cell = [tableView dequeueReusableCellWithIdentifier:AllPhotosReuseIdentifier forIndexPath:indexPath];
localizedTitle = NSLocalizedString(@"All Photos", @"");
} else {
cell = [tableView dequeueReusableCellWithIdentifier:CollectionCellReuseIdentifier forIndexPath:indexPath];
PHFetchResult *fetchResult = self.collectionsFetchResults[indexPath.section - 1];
PHCollection *collection = fetchResult[indexPath.row];
localizedTitle = collection.localizedTitle;
}
cell.textLabel.text = localizedTitle;
return cell;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
NSString *title = nil;
if (section > 0) {
title = self.collectionsLocalizedTitles[section - 1];
}
return title;
}
#pragma mark - PHPhotoLibraryChangeObserver
- (void)photoLibraryDidChange:(PHChange *)changeInstance
{
// Call might come on any background queue. Re-dispatch to the main queue to handle it.
dispatch_async(dispatch_get_main_queue(), ^{
NSMutableArray *updatedCollectionsFetchResults = nil;
for (PHFetchResult *collectionsFetchResult in self.collectionsFetchResults) {
PHFetchResultChangeDetails *changeDetails = [changeInstance changeDetailsForFetchResult:collectionsFetchResult];
if (changeDetails) {
if (!updatedCollectionsFetchResults) {
updatedCollectionsFetchResults = [self.collectionsFetchResults mutableCopy];
}
[updatedCollectionsFetchResults replaceObjectAtIndex:[self.collectionsFetchResults indexOfObject:collectionsFetchResult] withObject:[changeDetails fetchResultAfterChanges]];
}
}
if (updatedCollectionsFetchResults) {
self.collectionsFetchResults = updatedCollectionsFetchResults;
[self.tableView reloadData];
}
});
}
最佳答案
reason: '*** -[__NSArrayI objectAtIndex:]: index 2 beyond bounds [0 .. 0]'
很明显,您的数组没有您认为的那么多元素。在数组填充的地方放置一个断点,并仔细检查它是否符合预期。
关于ios - 未捕获的异常 'NSRangeException' ,原因 : '*** -[__NSArrayI objectAtIndex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27154016/
救命!我已经为这个问题苦恼了 1 个小时了。 我正在我的 .h 文件中创建一个数组 @interface LeftMenuViewController : UIViewController
我想使用 NSMutableArray 中的 ValueForKey 替换 objectAtIndex。我已经尝试了下面的代码,但是没有用,它崩溃了, [[students valueForKey:@
我有一个包含 10 个对象的 Array。我将第一个对象放入带有 String 的 Label 中。 然后我想要一个将 objectAtIndex 增加 1 的方法。 这是我的代码: //.m @in
我有 NSMutableArray “Tag”,其对象位于索引 0 上:“data”、“data1”、“data2”,索引 1:“data3”,索引 2:“data2” ...我选择的标签是“data
嗨,我有一个数组数组,我在添加某个索引后删除了一个对象。不知何故,我认为这表现得很奇怪,或者我可能忽略了一些事情。这是代码。我用 nslogs 对其进行跟踪。 for (int i = 0;
在我的 UIScrollView 中,我的数组中有 30 张图像。我尝试在数组中获取 objectAtIndex。我希望能够在 UIScrollView 停止滚动时在特定图像中显示动画。所以我在下面尝
如何在我的方法中获取 objectAtIndex。 例如,如果我使用 didSelectRowAtIndexPath:(NSIndexPath *)indexPath 我可以得到它 NSLog(@"
我正在尝试掌握 Objective C 和 Cocoa,所以我可能在这里使用了错误的术语。 我为一副纸牌创建了一个 Objective C 类,由我的主 AppDelegate.h 和 AppDele
我在使用 NSFetchedResultsController objectAtIndex 时出现内存泄漏:栈帧如下: 0 CoreFoundation __CFDataAllocate
我正在开发iOS应用程序。值存储在Array上,但是当我运行应用程序时,它崩溃,数组索引超出范围。请先帮助并谢谢。 代码: daysOfWeek = [NSArray arrayWithObjects
我有一个我想要一个值的 NSArray。 _membersArray = [_detailItem valueForKey:@"members"]; 当我使用此代码时: NSLog(@"%lu", (
我有一个 UITableView,它由从 XML 提要解析的数据数组填充。我正在努力寻找此错误的原因,并想知道是否有人可以帮助我。该错误不会经常发生。它仅在数组数量很大时发生,例如 10-15 个对象
我收到上述错误,但不知道为什么,因为我在另一个示例中实现了相同的代码。 “服务”是我的 NSMutableArray,“服务名称”是带有标签 2 的 TableView 上的标签。在 viewdidl
初学者 iOS 开发问题在这里。 我有以下格式的 plist: 我在我的应用程序中使用以下方法将这个 plist 转换为一个数组: NSMutableArray *array2 = [[NSMutab
我正在构建一个简单的 Swift CoreData TableView 应用程序。我已成功将数据保存到数据库并在 TableView 中重新加载数据。接下来我要做的是编辑这些数据。通过点击表格单元格/
所以我在这里有函数 collectionView: cellForItemAtIndexPath: func collectionView(collectionView: UICollectionVi
NSInteger *count = [monLessonArrayA count]; 对于 (i = 0; i < count; i++) { arrayVar = [monLessonArrayA
2012-06-15 17:53:25.532 BadgerNew[3090:707] *** Terminating app due to uncaught exception 'NSRangeEx
这个问题在这里已经有了答案: 关闭 9 年前。 Possible Duplicate: Is there some literal dictionary or array syntax in Obj
我有一个 NSArray,其中包含索引 0 - 9 的 10 个对象。数组中的每个条目都是一个引号。 当我的用户选择“随机引用”选项时,我希望能够从数组中选择一个随机条目并显示该条目中包含的文本。 有
我是一名优秀的程序员,十分优秀!