gpt4 book ai didi

ios - coreData Fetch 中的 NSInternalInconsistencyException

转载 作者:行者123 更新时间:2023-11-29 03:01:11 25 4
gpt4 key购买 nike

我试图在部分标题中显示客户名称,并在行中显示他的交易。我使用 coredata 和 NSFetched Results Controller 来实现这一点。但是我得到了一个 NSInternalconsistencyException。

 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
NSLog(@"number of sections %lu",[_fetchedResultsController sections].count);
return [[_fetchedResultsController sections] count];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
XXPerson *customer = [self.fetchedResultsController objectAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:section]];
NSLog(@"number of rows %lu",(unsigned long)[customer.transaction count]);
return [customer.transaction count];
}

- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
NSIndexPath *adjustedIndexPath = [NSIndexPath indexPathForRow:[indexPath section] inSection:0];
NSLog(@"Section: %ld, Row: %ld", (long)adjustedIndexPath.section, (long)adjustedIndexPath.row);
Customer *person = [[self fetchedResultsController] objectAtIndexPath:adjustedIndexPath];
NSSet *unsortedTransactions = [person transaction];
NSSortDescriptor *sort = [[NSSortDescriptor alloc]initWithKey:@"monthNumber" ascending:YES];
self.transactions = [unsortedTransactions sortedArrayUsingDescriptors: [NSArray arrayWithObjects: sort, nil]];
Transaction *transaction = [self.transactions objectAtIndex:[indexPath row]];
NSString *amountDepositedStr = [transaction valueForKey:@"amountDeposited"];
cell.textLabel.text = [NSString stringWithFormat:@"%@", amountDepositedStr];
NSLog(@"%@",[NSString stringWithFormat:@"%@", amountDepositedStr]);
}

日志是:

2014-04-25 12:23:04.277 CoreDataExample[2179:60b] number of sections 6
2014-04-25 12:23:04.286 CoreDataExample[2179:60b] number of sections 6
2014-04-25 12:23:04.288 CoreDataExample[2179:60b] number of rows 3
2014-04-25 12:23:04.288 CoreDataExample[2179:60b] number of rows 3
2014-04-25 12:23:04.289 CoreDataExample[2179:60b] number of rows 3
2014-04-25 12:23:04.289 CoreDataExample[2179:60b] number of rows 3
2014-04-25 12:23:04.290 CoreDataExample[2179:60b] number of rows 3
2014-04-25 12:23:04.290 CoreDataExample[2179:60b] number of rows 3
2014-04-25 12:23:04.292 CoreDataExample[2179:60b] Section: 0, Row: 0
2014-04-25 12:23:04.293 CoreDataExample[2179:60b] 20
2014-04-25 12:23:04.294 CoreDataExample[2179:60b] Section: 0, Row: 0
2014-04-25 12:23:04.295 CoreDataExample[2179:60b] 10
2014-04-25 12:23:04.296 CoreDataExample[2179:60b] Section: 0, Row: 0
2014-04-25 12:23:04.296 CoreDataExample[2179:60b] 110
2014-04-25 12:23:04.297 CoreDataExample[2179:60b] Section: 0, Row: 1
2014-04-25 12:23:04.298 CoreDataExample[2179:60b] 40
2014-04-25 12:23:04.299 CoreDataExample[2179:60b] Section: 0, Row: 1
2014-04-25 12:23:04.299 CoreDataExample[2179:60b] 30
2014-04-25 12:23:04.300 CoreDataExample[2179:60b] Section: 0, Row: 1
2014-04-25 12:23:04.300 CoreDataExample[2179:60b] 310
2014-04-25 12:23:04.301 CoreDataExample[2179:60b] Section: 0, Row: 2
2014-04-25 12:23:04.304 CoreDataExample[2179:60b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'no object at index 2 in section at index 0'
*** First throw call stack:
(
0 CoreFoundation 0x0000000101cbd495 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000101a1c99e objc_exception_throw + 43
2 CoreData 0x000000010035dc08 -[NSFetchedResultsController objectAtIndexPath:] + 408
3 CoreDataExample 0x0000000100003617 -[XXCustomerTableViewController configureCell:atIndexPath:] + 279
4 CoreDataExample 0x0000000100003a5e -[XXCustomerTableViewController tableView:cellForRowAtIndexPath:] + 142
5 UIKit 0x000000010069df8a -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 348
6 UIKit 0x0000000100683d5b -[UITableView _updateVisibleCellsNow:] + 2337
7 UIKit 0x0000000100695721 -[UITableView layoutSubviews] + 207
8 UIKit 0x0000000100629993 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 354
9 QuartzCore 0x00000001049df802 -[CALayer layoutSublayers] + 151
10 QuartzCore 0x00000001049d4369 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 363
11 QuartzCore 0x00000001049d41ea _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
12 QuartzCore 0x0000000104947fb8 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 252
13 QuartzCore 0x0000000104949030 _ZN2CA11Transaction6commitEv + 394
14 UIKit 0x00000001005c8024 _UIApplicationHandleEventQueue + 10914
15 CoreFoundation 0x0000000101c4cd21 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
16 CoreFoundation 0x0000000101c4c5f2 __CFRunLoopDoSources0 + 242
17 CoreFoundation 0x0000000101c6846f __CFRunLoopRun + 767
18 CoreFoundation 0x0000000101c67d83 CFRunLoopRunSpecific + 467
19 GraphicsServices 0x0000000103ceef04 GSEventRunModal + 161
20 UIKit 0x00000001005c9e33 UIApplicationMain + 1010
21 CoreDataExample 0x0000000100007553 main + 115
22 libdyld.dylib 0x00000001023555fd start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

最佳答案

尝试将 configureCell: 更改为

- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath 
{
NSIndexPath *adjustedIndexPath = [NSIndexPath indexPathForRow:0 inSection:[indexPath section]];
....
}

关于ios - coreData Fetch 中的 NSInternalInconsistencyException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23286865/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com