我收到偶爾崩潰當我嘗試使用UISearchBar
/searchDisplayController
搜索某些文本時。我正在通過JSON從在線數據庫中搜索數據,並且99%的時間內一切正常。我正在使用textDidChange
委託方法在其搜索中搜索用戶類型。iOS在線搜索數據庫時遇到NSRangeException崩潰
這裏是崩潰我得到的一個例子:
Fatal Exception: NSRangeException
-[__NSCFArray objectAtIndex:]: index (2) beyond bounds (2)
或
Fatal Exception: NSRangeException
*** -[__NSArrayI objectAtIndex:]: index 6 beyond bounds [0 .. 0]
這真的很難讓我明確了什麼是給我的崩潰,因爲當我嘗試重新什麼造成了事故,我不能。該應用程序可以很好地工作幾天,並進行大量「測試」(例如,我一遍又一遍地輸入查詢)。然後隨機會崩潰,然後幾天沒有。
以下是一些更新我的TableViews
的委託方法。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [[SearchInfo sharedInfo].searchArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
////////Adds search data to local Array to pass it around the applicatio//////
searchData = [[SearchInfo sharedInfo].searchArray objectAtIndex:indexPath.row];
static NSString *cellIdentifier = @"Cell";
//Standard Table View Cell
UITableViewCell *searchCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (searchCell==nil) {
searchCell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
///////////Search bar tableview//////////
if (tableView == self.searchDisplayController.searchResultsTableView) {
searchCell.textLabel.text = [SearchData objectForKey:@"title"];
searchCell.detailTextLabel.text = [SearchData objectForKey:@"system_title"];
}
///////Builds the custom tableview cell//////
UILabel *searchTitleLabel = (UILabel*)[searchCell viewWithTag:1];
searchTitleLabel.text = [searchData objectForKey:@"title"];
UILabel *systemTitleLabel = (UILabel *)[searchCell viewWithTag:2];
systemTitleLabel.text = [searchData objectForKey:@"system_title"];
UILabel *devLabel = (UILabel*)[searchDataCell viewWithTag:3];
if([[searchData objectForKey:@"developer"] isKindOfClass:[NSString class]])
{
if([[searchData objectForKey:@"developer"] isEqualToString:@""] || [[searchData objectForKey:@"developer"] isEqualToString:@"<null>"])
{
developerLabel.text = @"Unknown";
}
else {
developerLabel.text = [NSString stringWithFormat:@"%@",[searchData objectForKey:@"developer"]];
}
}
else {
developerLabel.text = @"Unknown";
}
////////////////////////////////////////////////////////////////
return searchCell;
}
如果您還有其他問題,請告訴我!我在這裏拉我的頭髮。
這裏是崩潰日誌:
Thread : Fatal Exception: NSRangeException
0 CoreFoundation 0x2577cc1f __exceptionPreprocess + 126
1 libobjc.A.dylib 0x32f27c8b objc_exception_throw + 38
2 CoreFoundation 0x25691a8d CFRunLoopRemoveTimer
3 Archive.vg 0x00073ddb -[CenterViewController tableView:cellForRowAtIndexPath:] (CenterViewController.m:192)
4 UIKit 0x28f018c7 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 474
5 UIKit 0x28f0198b -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 54
6 UIKit 0x28ef70e1 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2268
7 UIKit 0x28d0f2ff -[UITableView layoutSubviews] + 186
8 UIKit 0x28c394d7 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 514
9 QuartzCore 0x28661a0d -[CALayer layoutSublayers] + 136
10 QuartzCore 0x2865d3e5 CA::Layer::layout_if_needed(CA::Transaction*) + 360
11 QuartzCore 0x2865d26d CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 16
12 QuartzCore 0x2865cc51 CA::Context::commit_transaction(CA::Transaction*) + 224
13 QuartzCore 0x2865ca55 CA::Transaction::commit() + 324
14 QuartzCore 0x2865692d CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 56
15 CoreFoundation 0x257433b5 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 20
16 CoreFoundation 0x25740a73 __CFRunLoopDoObservers + 278
17 CoreFoundation 0x25740e7b __CFRunLoopRun + 914
18 CoreFoundation 0x2568f211 CFRunLoopRunSpecific + 476
19 CoreFoundation 0x2568f023 CFRunLoopRunInMode + 106
20 GraphicsServices 0x2ca880a9 GSEventRunModal + 136
21 UIKit 0x28c9b1d1 UIApplicationMain + 1440
22 Archive.vg 0x0009d0cd main (main.m:16)
23 libdyld.dylib 0x334a7aaf start + 2
沒關係所有的代碼。只需顯示崩潰發生的代碼_,請。 – matt 2014-10-28 20:49:53
'[SearchInfo sharedInfo] .searchArray'正在發生明顯變化。您應該將其鎖定,以便在對'numberOfRowsInSection:'和'cellForRowAtIndexPath:'的調用之間不發生變化。 – 2014-10-28 20:51:34
@matt我添加了一個崩潰日誌。它與SIGABRT崩潰。當我回家時,我會添加一個異常斷點。 – DookieMan 2014-10-28 20:57:20