gpt4 book ai didi

ios - 为什么滑动以删除并拉动刷新会导致崩溃?

转载 作者:行者123 更新时间:2023-12-01 16:36:09 25 4
gpt4 key购买 nike

NSDictionary *parameters = @{@"min_id": minID};中有一个小错误。当我滑动以删除然后拉动刷新时,应用程序崩溃。

这是我正在使用的代码:

- (void)requestNewItemsWithCompletionHandler:

(NewItemCompletionBlock)completionHandler {
self.thereAreNoMoreOlderMessages = NO;
if (self.isRefreshing == NO) {
self.isRefreshing = YES;

// Need to add images here

NSString *minID = [[self.mediaItems firstObject] idNumber];
NSDictionary *parameters = @{@"min_id": minID};

[self populateDataWithParamaters:parameters completionHandler:^(NSError *error) {
self.isRefreshing = NO;

if (completionHandler) {
completionHandler(error);
}
}];
}
}

这是打印到控制台的错误消息:
2015-01-26 21:16:43.596 BlocstagramThird[43722:2760784] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(
0 CoreFoundation 0x000000011087cf35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000110515bb7 objc_exception_throw + 45
2 CoreFoundation 0x000000011078861f -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 383
3 CoreFoundation 0x000000011079b64b +[NSDictionary dictionaryWithObjects:forKeys:count:] + 59
4 BlocstagramThird 0x000000010ffd5012 -[DataSource requestNewItemsWithCompletionHandler:] + 322
5 BlocstagramThird 0x000000010ffda2bd -[ImagesTableViewController refreshControlDidFire:] + 173
6 UIKit 0x0000000110ead8be -[UIApplication sendAction:to:from:forEvent:] + 75
7 UIKit 0x0000000110fb4410 -[UIControl _sendActionsForEvents:withEvent:] + 467
8 UIKit 0x0000000111598a29 -[UIRefreshControl _setRefreshControlState:notify:] + 318
9 libdispatch.dylib 0x0000000112ffcba6 _dispatch_call_block_and_release + 12
10 libdispatch.dylib 0x000000011301a7f4 _dispatch_client_callout + 8
11 libdispatch.dylib 0x0000000113001ede _dispatch_after_timer_callback + 334
12 libdispatch.dylib 0x000000011301a7f4 _dispatch_client_callout + 8
13 libdispatch.dylib 0x000000011301109a _dispatch_source_latch_and_call + 852
14 libdispatch.dylib 0x00000001130096d2 _dispatch_source_invoke + 412
15 libdispatch.dylib 0x0000000113003771 _dispatch_main_queue_callback_4CF + 555
16 CoreFoundation 0x00000001107e4fe9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
17 CoreFoundation 0x00000001107a7eeb __CFRunLoopRun + 2043
18 CoreFoundation 0x00000001107a7486 CFRunLoopRunSpecific + 470
19 GraphicsServices 0x0000000114d909f0 GSEventRunModal + 161
20 UIKit 0x0000000110eac420 UIApplicationMain + 1282
21 BlocstagramThird 0x000000010ffd9113 main + 115
22 libdyld.dylib 0x000000011304f145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

以下是与滑动删除相关的代码:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
Media *item = [self items][indexPath.row];
[[DataSource sharedInstance] deleteMediaItem:item];
}
}

最佳答案

该错误表明您正在尝试将nil对象(根据代码示例为minID)添加到字典中,这是不允许的。

您可以在执行以下操作之前验证minID:

NSDictionary *parameters = nil;
if (self.mediaItems.count) {
parameters = @{@"min_id": minID};

假设populateDataWithParameters方法可以接受nil参数。如果不能,则还需要保护该 call 。

关于ios - 为什么滑动以删除并拉动刷新会导致崩溃?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28097614/

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