gpt4 book ai didi

ios - dequeueReusableCellWithIdentifier 在 iPad 上崩溃(使用 iOS 5)

转载 作者:行者123 更新时间:2023-11-28 20:22:10 25 4
gpt4 key购买 nike

我附加了一个 TableViewController 和一个 SearchDisplayController。它检查当前 tableView 是搜索还是正常,然后设置变量,然后使用此数据填充表。这是来源:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *item;
if(tableView == self.searchDisplayController.searchResultsTableView){
item = [self.search objectAtIndex:indexPath.row];
} else {
item = [self.results objectAtIndex:indexPath.row];
}
static NSString *CellIdentifier = @"Cell";

/********* ERROR HAPPENS HERE!!!!! **********/
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"Cell"];
/*********************************************/

if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

UIImageView *iconView = [[UIImageView alloc] initWithFrame:CGRectMake(5.0, 5.0, 44.0, 44.0)];
iconView.tag = 100;
[cell.contentView addSubview:iconView];

UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(57.0, 5.0, 249.0, 29.0)];
title.tag = 101;
title.font = [UIFont fontWithName:@"AmericanTypewriter-Bold" size:15.0];
title.textColor = [UIColor colorWithRed:255.0f/255.0f green:128.0f/255.0f blue:0.0f/255.0f alpha:1.0];
[cell.contentView addSubview:title];

UILabel *subtitle = [[UILabel alloc] initWithFrame:CGRectMake(57.0, 28.0, 249.0, 21.0)];
subtitle.tag = 102;
subtitle.font = [UIFont fontWithName:@"HelveticaNeue-Medium" size:12.0];
subtitle.textColor = [UIColor colorWithRed:179.0f/255.0f green:179.0f/255.0f blue:179.0f/255.0f alpha:1.0];
[cell.contentView addSubview:subtitle];
} else {
UIImageView *iconView = (UIImageView *)[cell viewWithTag:100];
if([[item valueForKey:@"categories"] count] == 0){
UIImage *img = [UIImage imageNamed:@"venue"];
iconView.frame = CGRectMake(iconView.frame.origin.x, iconView.frame.origin.y, img.size.width, img.size.height);
[iconView setImage: img];
} else {
NSDictionary *iconDict = [[[item valueForKey:@"categories"] objectAtIndex:0] valueForKey:@"icon"];
NSString *icon = [NSString stringWithFormat:@"%@bg_44%@", [iconDict valueForKey:@"prefix"], [iconDict valueForKey:@"suffix"]];
[iconView setImageWithURL:[NSURL URLWithString:icon] placeholderImage:[UIImage imageNamed:@"venue"]];
}
UILabel *title = (UILabel *)[cell viewWithTag:101];
title.text = [item valueForKey:@"name"];
UILabel *subtitle = (UILabel *)[cell viewWithTag:102];
subtitle.text = [[item valueForKey:@"location"] valueForKey:@"address"];
}
UIView *bgColorView = [[UIView alloc] init];
[bgColorView setBackgroundColor:[UIColor colorWithRed:255.0f/255.0f green:128.0f/255.0f blue:0.0f/255.0f alpha:1.0]];
[cell setSelectedBackgroundView:bgColorView];
return cell;
}

我一直被一个错误困扰,每当代码遇到它尝试 dequeueReusableCell 的行时,该错误就会使应用程序崩溃。在大多数现代 iOS 设备中它都可以工作。我已经看到它在我的 iPhone5、 friend 的 iPhone4 和更新版本的 iPad 上运行。但是在某些设备中——包括我的第一代 iPad(安装了 iOS5)——这条线会崩溃。没有有用的错误消息。我得到的只是典型的“(lldb)”消息。甚至没有数组越界类型的异常。堆栈跟踪仅显示它在 dequeueReusableCellWithIdentifier 内部中断。这是堆栈跟踪:

2013-03-17 17:32:30.350 Streetgram[861:707] *** Assertion failure in -[UINib lazyArchiveData], /SourceCache/UIKit/UIKit-1914.85/UINib.m:210
2013-03-17 17:32:30:373 Streetgram[861:1799] -[SearchViewController tableView:cellForRowAtIndexPath:] [Line 115] Uncaught exception: UINib must be instantiated with either data or a nib name.
2013-03-17 17:32:30:431 Streetgram[861:1799] -[SearchViewController tableView:cellForRowAtIndexPath:] [Line 116] Stack trace: (
0 CoreFoundation 0x35c508a7 __exceptionPreprocess + 186
1 libobjc.A.dylib 0x33874259 objc_exception_throw + 32
2 CoreFoundation 0x35c50789 +[NSException raise:format:] + 0
3 Foundation 0x350443a3 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 90
4 UIKit 0x335c7a47 -[UINib lazyArchiveData] + 186
5 UIKit 0x335c7b97 -[UINib unarchiverForInstantiatingReturningError:] + 78
6 UIKit 0x335c7d8f -[UINib instantiateWithOwner:options:] + 98
7 UIKit 0x333b17bd -[UITableView dequeueReusableCellWithIdentifier:] + 304
8 Streetgram 0x00104157 -[SearchViewController tableView:cellForRowAtIndexPath:] + 762
9 UIKit 0x333b0efb -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 546
10 UIKit 0x333affd9 -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1076
11 UIKit 0x333af763 -[UITableView layoutSubviews] + 206
12 UIKit 0x33353f15 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 148
13 CoreFoundation 0x35baf1fb -[NSObject performSelector:withObject:] + 42
14 QuartzCore 0x32d7aaa5 -[CALayer layoutSublayers] + 216
15 QuartzCore 0x32d7a6bd _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 216
16 QuartzCore 0x32d7e843 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 226
17 QuartzCore 0x32d7e57f _ZN2CA11Transaction6commitEv + 314
18 QuartzCore 0x32d764b9 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 56
19 CoreFoundation 0x35c24b1b __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 18
20 CoreFoundation 0x35c22d57 __CFRunLoopDoObservers + 258
21 CoreFoundation 0x35c230b1 __CFRunLoopRun + 760
22 CoreFoundation 0x35ba64a5 CFRunLoopRunSpecific + 300
23 CoreFoundation 0x35ba636d CFRunLoopRunInMode + 104
24 GraphicsServices 0x33941439 GSEventRunModal + 136
25 UIKit 0x3337ecd5 UIApplicationMain + 1080
26 Streetgram 0x001007c9 main + 116
27 Streetgram 0x00100750 start + 40
....

知道为什么会这样吗?

最佳答案

当您将可重用单元格出列时,您应该使用参数中传递的 tableView 而不是您自己已知的 self.tableView。对于搜索 View ,这两个将不相同,这可能会导致问题。像这样:

UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

关于ios - dequeueReusableCellWithIdentifier 在 iPad 上崩溃(使用 iOS 5),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15466258/

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