我有一個本地的SQLite數據庫,並需要返回大量的記錄。加載需要幾秒鐘,所以我想添加一個活動指示器。活動指示器似乎正在運行,但問題是池不允許數組返回任何值,如下所示。加載sqlite本地數據庫時顯示活動指標
- (void)viewDidLoad
{
[super viewDidLoad];
activityIndicator = [[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray] autorelease];
activityIndicator.frame = CGRectMake(0.0, 0.0, 48.0, 48.0);
activityIndicator.center = self.view.center;
[self.view addSubview:activityIndicator];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[activityIndicator startAnimating];
[self performSelectorInBackground:@selector(loadData) withObject:nil];
}
//What I need to load from SQLITE
-(void)loadData {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // Path to the database
//CODED HERE FOR DATABASE TO OPEN AND QUERY HERE TO BUILD ARRAYS
NSString *firstField = [NSString stringWithUTF8String:cFirst];
NSString *secondField = [NSString stringWithUTF8String:cSecond];
NSString *thirdField = [NSString stringWithUTF8String:cThird];
[FirstArray addObject:firstField];
[SecondArray addObject:secondField];
[ThirdArray addObject:thirdField];
//Checking to see if records are being added to the arrays
NSString *recordAdded = [NSString stringWithFormat:@"%@ - %@ - %@", firstField, secondField, thirdField];
NSLog(@"Song: %@", recordAdded);
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[activityIndicator stopAnimating];
[pool release];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
NSString *firstValue = [firstArray objectAtIndex:indexPath.row];
NSString *secondValue = [secondArray objectAtIndex:indexPath.row];
NSString *thirdValue = [thirdArray objectAtIndex:indexPath.row];
NSString *details = [NSString stringWithFormat:@"%@ - %@", secondValue, thirdValue];
cell.textLabel.text = cellValue;
cell.detailTextLabel.text = details ;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
當我在查看調試器時,看到數組正在構建爲活動指示器。問題是,我認爲池發佈也釋放我的陣列。
當我不添加池和活動指示器時,代碼返回表視圖中的查詢正常。
任何人都可以幫助指出我在正確的方向不釋放數組,如果這是發生在這裏?任何形式的幫助將不勝感激。 :-)
---另外---另外--- 環顧更多後,我發現我必須將數組傳回主線程。這是我通過在線搜索收集到的。
[self performSelectorOnMainThread:@selector(done:) withObject:cellData waitUntilDone:NO];
我該如何去裝載這些數組的表?
末增加
[tableview reloadData]
其實你是對的,是沒有工作,我的表被加載快過了,謝謝:-) – Far 2012-07-06 16:43:45歡迎SO,遠!如果瑞克的答案是最好的答案並幫助你,那麼一定要通過點擊他答案旁邊的複選標記來接受它,這樣他才能得到你的幫助! – lnafziger 2012-07-06 16:53:27