2012-10-08 39 views
0

我想使用tableview + searchDisplay与两个不同的来源,也就是说,当用户尝试搜索searchbar时,它应该从不同的数组搜索并显示它。ios tableview尽快搜索开始

我能做到这一点的方法是,在表视图委托中区分源,并在searchdisplay调用表视图委托方法时处理不同的源。所以,我不喜欢的东西:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    if(self.tableView == tableView){ 
    return [self.sourceArray objectAtIndex:section] count]; 
    } 
    //search display 
    return 5; 

} 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return self.tableView == tableView ? 3 : 1; 
} 

但一旦我试图在搜索栏搜索(只要文本发生变化),它只是 索引越界坠毁。我试图调试它,但无法找到真正的错误。

2012-10-08 14:36:27.075 Apps[14496:907] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 2 beyond bounds [0 .. 1]' 
*** First throw call stack: 
(0x37b9b2a3 0x35eab97f 0x37ae5e8d 0x391f6221 0x38ea1fef 0x38e9cd09 0x38eb58f9 0x38eb54f9 0x2934773 0x38fd2ac5 0x38fca943 0x38fca8ff 0x38f5c48f 0x38f94235 0x38f93ac5 0x37aec037 0x355aed91 0x3710c1e5 0x372ded6b 0x372e0f03 0x372e0e1d 0x372e0cff 0x372d64dd 0x372e0c3d 0x372e094f 0x372e03df 0x372e0237 0x372e0115 0x370a97bd 0x370a9135 0x370a8d8f 0x370a8d51 0x370a8c83 0x37260d17 0x372dff2b 0x372dfe5d 0x3449d689 0x372d520b 0x344c35ef 0x38fcf041 0x38fceff9 0x2950f0d 0x38f9c151 0x38f9a049 0x292f711 0x38f998b7 0x38f983ad 0x294dc4f 0x38f97737 0x38e7f5f9 0x38e6c809 0x38e6c123 0x3801f5a3 0x3801f1d3 0x37b70173 0x37b70117 0x37b6ef99 0x37ae1ebd 0x37ae1d49 0x3801e2eb 0x38ec0301 0x6190d 0x593e8) 
libc++abi.dylib: terminate called throwing an exception 

我不确定在哪里出现这种出界异常发生在,我会很感激任何评论。

+0

你有一个断点异常? – FluffulousChimp

+0

你可以发布所有的输出?什么是** self.sourceArray **? – Pablosproject

+0

你没有在这里发布的是你的“tableView:cellForRowAtIndexPath:”例程。这可能会告诉我们在哪里崩溃。 –

回答

0

你用委托方法

  • (无效)searchBarTextDidBeginEditing:(*的UISearchBar)搜索栏;
  • (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar;
  • (void)searchBar:(UISearchBar *)searchBar1 textDidChange:(NSString *)searchText fbFriendList_table;
  • (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar;
  • (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar;