2015-05-28 1 views
1

С помощью UISearchDisplayController можно ли использовать метод вызова tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath, не вызывая источник данных для фактического количества строк?UITableView перерисовка без вызова источника данных

Вот трассировки стека для аварии (IOS 7.1.2):

Hardware Model:  iPhone4,1 

Application Specific Information: 
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array' 

Last Exception Backtrace: 
0 CoreFoundation      0x3085df83 __exceptionPreprocess + 131 
1 libobjc.A.dylib      0x3b0d8ccf objc_exception_throw + 36 
2 CoreFoundation      0x307947cb -[__NSArrayM objectAtIndex:] + 228 
3 MyApp        0x0016cbb3 -[BaseContactsViewController tableView:cellForRowAtIndexPath:] (BaseContactsViewController.m:338) 
4 UIKit        0x331ad8f7 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 408 
5 UIKit        0x33154c27 -[UITableView _updateVisibleCellsNow:] + 1804 
6 UIKit        0x33147c5d -[UITableView _setNeedsVisibleCellsUpdate:withFrames:] + 166 
7 UIKit        0x33147ba3 -[UITableView _rectChangedWithNewSize:oldSize:] + 480 
8 UIKit        0x331541cd -[UITableView setBounds:] + 262 
9 UIKit        0x3317066d -[UIView(Geometry) _applyISEngineLayoutValues] + 278 
10 UIKit        0x33094549 -[UIView(Geometry) _resizeWithOldSuperviewSize:] + 162 
11 UIKit        0x33172ca3 -[UIScrollView _resizeWithOldSuperviewSize:] + 40 
12 CoreFoundation      0x307a2abd __53-[__NSArrayM enumerateObjectsWithOptions:usingBlock:]_block_invoke + 90 
13 CoreFoundation      0x307a29cb -[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 196 
14 UIKit        0x330851bd -[UIView(Geometry) resizeSubviewsWithOldSize:] + 118 
15 UIKit        0x331712e9 -[UIView(AdditionalLayoutSupport) _is_layout] + 134 
16 UIKit        0x3307afc1 -[UIView(Hierarchy) layoutSubviews] + 70 
17 UIKit        0x3307ad59 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 378 
18 QuartzCore       0x32cf862b -[CALayer layoutSublayers] + 140 
19 QuartzCore       0x32cf3e3b CA::Layer::layout_if_needed(CA::Transaction*) + 348 
20 UIKit        0x3308fe8b -[UIView(Hierarchy) layoutBelowIfNeeded] + 548 
21 UIKit        0x33129eeb -[UINavigationController _layoutViewController:] + 808 
22 UIKit        0x331ddcc5 -[UINavigationController _setNavigationBarHidden:edge:duration:] + 1270 
23 UIKit        0x3326c011 -[UINavigationController _setNavigationBarHidden:edgeIfNotNavigating:duration:] + 530 
24 UIKit        0x33196109 -[UISearchDisplayController setActive:animated:] + 8614 
25 UIKit        0x3326abcd -[UISearchDisplayController searchBarTextDidBeginEditing:] + 246 
26 UIKit        0x3326aaaf -[UISearchBar(UISearchBarStatic) _searchFieldBeginEditing] + 88 
27 UIKit        0x330b0037 -[UIApplication sendAction:to:from:forEvent:] + 88 
28 UIKit        0x330affd7 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 28 
29 UIKit        0x330affb1 -[UIControl sendAction:to:forEvent:] + 42 
30 UIKit        0x3309b717 -[UIControl _sendActionsForEvents:withEvent:] + 372 
31 UIKit        0x3309acfd -[UITextField willAttachFieldEditor:] + 666 
32 UIKit        0x33097805 -[UIFieldEditor becomeFieldEditorForView:] + 818 
33 UIKit        0x33176f15 -[UITextField _becomeFirstResponder] + 158 
34 UIKit        0x3326a91f -[UISearchBarTextField _becomeFirstResponder] + 76 
35 UIKit        0x330f9127 -[UIResponder becomeFirstResponder] + 360 
36 UIKit        0x330f93e7 -[UIView(Hierarchy) becomeFirstResponder] + 104 
37 UIKit        0x33175c17 -[UITextField becomeFirstResponder] + 44 
38 UIKit        0x333fe579 -[UISearchBar(UISearchBarStatic) becomeFirstResponder] + 34 
39 UIKit        0x33200fed _UIGestureRecognizerSendActions + 194 
40 UIKit        0x330ac4e3 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 1136 
41 UIKit        0x33453aed ___UIGestureRecognizerUpdate_block_invoke + 46 
42 UIKit        0x33073353 _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 216 
43 UIKit        0x33071a9b _UIGestureRecognizerUpdate + 280 
44 UIKit        0x330aad49 -[UIWindow _sendGesturesForEvent:] + 770 
45 UIKit        0x330aa66f -[UIWindow sendEvent:] + 664 
46 UIKit        0x3307f8cd -[UIApplication sendEvent:] + 194 
47 UIKit        0x3307df77 _UIApplicationHandleEventQueue + 7100 
48 CoreFoundation      0x3082920b __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 12 
49 CoreFoundation      0x308286db __CFRunLoopDoSources0 + 204 
50 CoreFoundation      0x30826ecf __CFRunLoopRun + 620 
51 CoreFoundation      0x30791ebf CFRunLoopRunSpecific + 520 
52 CoreFoundation      0x30791ca3 CFRunLoopRunInMode + 104 
53 GraphicsServices      0x356eb663 GSEventRunModal + 136 
54 UIKit        0x330de14d UIApplicationMain + 1134 
55 MyApp        0x0013f55b main (main.m:16) 
56 libdyld.dylib      0x3b5e5ab7 start + 0 

Как я понимаю, это был кран в панели поиска поле редактирования и поиска был начат. Если у нас есть правильное количество строк из источника данных, невозможно исключить такое исключение. Поэтому мое предложение - источник данных, который не запрашивался для количества строк.

Вот моя реализация источника данных:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    if (_searchDisplayController.active) 
    { 
     // return number of search items 
    } 

    // return number of regular items in section 
} 

Я использую active свойство знать, если мне нужно, чтобы обеспечить количество элементов поиска вместо обычных предметов. Мое другое предложение состоит в том, что по какой-то причине контроллер поиска не был активен во время вызова источника данных, но был активен во время вызова делегата таблицы.

ответ

0

Да. Для tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath вы можете просто вернуть пустую ячейку, не представляя источник данных.

tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    return cell; 
} 

Ваш авария вызван BaseContactsViewController.m:338. Вы пытаетесь получить объект с индексом 0 из пустого набора данных. Что у вас на этой линии?

+0

AFAIK, если numberOfSectionsInTableView: возвращено ноль, cellForRowAtIndexPath: не будет вызываться. Таким образом, исключить пустое выделение массива невозможно. –

+0

Ваше предложение в сообщении верно. UISearchDisplayController не вызывает numberOfSectionsInTableView: если вы установите в нем точку останова, она не будет ломаться. Я испытал это в одном из моих проектов. Я хочу избежать UISearchDisplayController для этой путаницы. Также он устарел https://developer.apple.com/library/ios/documentation/UIKit/Reference/UISearchDisplayController_Class/ – Bigman

+0

Думаю, теперь я понимаю ваш вопрос. На вопрос, я думаю, что невозможно иметь tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath, вызываемый без вызова источника данных для фактического количества строк. – Bigman

 Смежные вопросы

  • Нет связанных вопросов^_^