我從動態的API使用UISearchBar
加載數據,並試圖顯示它,使用這樣的事情:EXC_BAD_ACCESS上ReloadData
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
[searchBar resignFirstResponder];
NSLog(@"Search Text: %@",[searchBar text]);
[self startSearchingWithText:[searchBar text]];
}
- (void) startSearchingWithText:(NSString *)text {
...
// Go through the list of services and set up a query for the search term
QueryServiceManager *manager = [[QueryServiceManager alloc] initWithServices: services];
// Set up the query
if (![manager addKeyword: text])
NSLog(@"PROBLEM!");
// Execute the query and store the titles in an array
self.data = [[manager makeQuery] copy]; // Returns a NSArray
NSLog(@"%@",self.data);
// Add the items to the tableView
[self.tableView reloadData];
我UITableViewController
代碼設置爲從self.data閱讀,這最初@""
元素的NSArray
,因爲這樣的:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
[self.data count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell...
cell.textLabel.text = [self.data objectAtIndex:indexPath.row];
return cell;
}
我得到的,當我做到這一點:
(GDB)繼續 2010-02-26 18:43:32.515 ISAVE [11690:207]( 「東芝Satellite L505-GS5037 TruBrite 15.6英寸的筆記本電腦(黑色)」, 「戴爾靈11 11.6英寸黑曜石黑色筆記本電腦(Windows 7 Premium)「, 」華碩Eee PC貝殼1005PE-MU17-BK 10.1英寸黑色上網本 - 長達11小時的電池壽命「, 」SwissGear電腦揹包(紅色)「, 」Belkin 36- (黑色)「 」Compaq EVO N610C「, 」Belkin F8E062帶黑色錶殼(去磁工具)的55件計算機工具套件「, 」華碩Eee PC貝殼1005PE-PU17-BK 10.1 - 英國黑色上網本 - 長達14小時的電池壽命「, 」Harman Kardon SoundSticks II 2.1即插即用多媒體揚聲器系統「, 」ION音頻錄像機2 PC USB VHS視頻到電腦轉換器「 ) (gdb)繼續 編程接收信號:」EXC_BAD_ACCESS「。 (gdb)
任何想法?它看起來像NSArray
被正確填充,那麼事情是失敗的ON/reloadData調用後(斷點證實這一點,但不能隔離,事情會出錯)
編輯:我更換了NSLog()
與枚舉
for (NSString *elem in self.data)
NSLog(elem);
而且它仍然崩潰。我設法哄日誌出來的:http://pastebin.com/NDVKLsJC
當我刪除了NSLog()
完全,它不會崩潰,但UITableView
不更新,要麼。
你在哪裏調用reloadData? – nickthedude
哦,我從來沒有見過它 – nickthedude
在上面的NSLog()命令。當「搜索」按鈕被擊中時,該功能被自動調用。發佈編輯以顯示完整的定義。 –