我有一个本地的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