と が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、友人の iPhone4、そして新しいバージョンの iPad で動作するのを見てきました。ただし、一部のデバイス (私の第 1 世代の 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
....
なぜこれが起こっているのですか?