您好,我想知道您是否可以帮我解决如何阻止我的应用停止并使用100%CPU:
基本上是将Feed添加到包含特定字符串的项目中,当它只是几个字符串时它会检查它然后很好,但是当它4+时然后它停止,更多的字符串检查更长时间停止。我怎样才能更好地优化它?
我试图将其隐藏在加载图标后面,但它在加载图标之前停止。
需要更多信息,请告知我们。感谢
代码
if(self.segmentedControl.selectedSegmentIndex == 1){
NSLog(@"RELOADED SEGMENTED");
//NSArray *defaults = [[NSUserDefaults standardUserDefaults] objectForKey:@"favTeams"];
if(favFilters.count > 0){
//[subPredsOr addObject:[NSPredicate predicateWithFormat:@"articleTeam IN %@", favFilters]];
for(NSString *text in favFilters){
//[subPredsOr addObject:[NSPredicate predicateWithFormat:@"articleText CONTAINS[c] %@",text]];
[subPredsOr addObject:[NSPredicate predicateWithFormat:@"ANY rumourToTag.tagName =[cd] %@",text]];
}
predFav = [NSCompoundPredicate orPredicateWithSubpredicates:subPredsOr];
}
[SVProgressHUD dismiss];
}
if(subPredsOr.count > 0)
[subPreds addObject:predFav];
NSPredicate *pred = [NSCompoundPredicate andPredicateWithSubpredicates:subPreds];
NSLog(@"Pred: %@", pred);
[fetchRequest setPredicate:pred];
// Set the batch size to a suitable number.
[fetchRequest setFetchBatchSize:30];
if(![self.isFav boolValue])
[fetchRequest setFetchLimit:70];
** [编辑] **完整方法:
- (NSFetchedResultsController *)fetchedResultsController
{
if (__fetchedResultsController != nil) {
return __fetchedResultsController;
}
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
// Edit the entity name as appropriate.
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Rumour" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
if ([self.isComps boolValue]) {
NSError *errorb;
NSArray *items = [self.managedObjectContext executeFetchRequest:fetchRequest error:&errorb];
for (NSManagedObject *managedObject in items) {
[self.managedObjectContext deleteObject:managedObject];
}
}
NSPredicate *p;
// #if defined(FRLITE)
// p = [NSPredicate predicateWithFormat:@"(isLite == 1) AND (isAndroid == 0)"];
// #else
// p = [NSPredicate predicateWithFormat:@"(isLitePromo == 0) AND (isAndroid == 0)"];
// #endif
NSMutableArray *subPreds = [NSMutableArray array];
//[subPreds addObject:p];
NSMutableArray *subPredsOr = [NSMutableArray array];
NSPredicate *predFav;
if([self.isNews boolValue]){
NSPredicate *p = [NSPredicate predicateWithFormat:@"ANY rumourToTag.tagName =[cd] 'news'"];
[subPreds addObject:p];
}
if([self.isVirals boolValue]){
NSPredicate *p = [NSPredicate predicateWithFormat:@"ANY rumourToTag.tagName =[cd] 'virals'"];
[subPreds addObject:p];
}
if([self.isComps boolValue]){
NSPredicate *p = [NSPredicate predicateWithFormat:@"ANY rumourToTag.tagName =[cd] 'competitions'"];
[subPreds addObject:p];
}
if([self.isPopular boolValue]){
NSPredicate *p;
if([self.popularSelector isEqualToString:@"popularDay"]){
p = [NSPredicate predicateWithFormat:@"isPopularDay == 1"];
}
if([self.popularSelector isEqualToString:@"popularWeek"]){
p = [NSPredicate predicateWithFormat:@"isPopularWeek == 1"];
}
[subPreds addObject:p];
}
if(self.segmentedControl.selectedSegmentIndex == 1){
NSLog(@"RELOADED SEGMENTED");
//NSArray *defaults = [[NSUserDefaults standardUserDefaults] objectForKey:@"favTeams"];
if(favFilters.count > 0){
//[subPredsOr addObject:[NSPredicate predicateWithFormat:@"articleTeam IN %@", favFilters]];
for(NSString *text in favFilters){
//[subPredsOr addObject:[NSPredicate predicateWithFormat:@"articleText CONTAINS[c] %@",text]];
[subPredsOr addObject:[NSPredicate predicateWithFormat:@"ANY rumourToTag.tagName =[cd] %@",text]];
}
predFav = [NSCompoundPredicate orPredicateWithSubpredicates:subPredsOr];
}
[SVProgressHUD dismiss];
}
if(subPredsOr.count > 0)
[subPreds addObject:predFav];
NSPredicate *pred = [NSCompoundPredicate andPredicateWithSubpredicates:subPreds];
NSLog(@"Pred: %@", pred);
[fetchRequest setPredicate:pred];
// Set the batch size to a suitable number.
[fetchRequest setFetchBatchSize:30];
if(![self.isFav boolValue])
[fetchRequest setFetchLimit:70];
// Edit the sort key as appropriate.
NSSortDescriptor *sortDescriptor;
if([self.isPopular boolValue])
sortDescriptor = [[NSSortDescriptor alloc] initWithKey:self.popularSelector ascending:YES];
else
sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"articleDate" ascending:NO];
NSArray *sortDescriptors = [NSArray arrayWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
// Edit the section name key path and cache name if appropriate.
// nil for section name key path means "no sections".
NSString *sectionKeyPath = @"customSectionTitle";
if([self.isPopular boolValue])
sectionKeyPath = nil;
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:sectionKeyPath cacheName:nil];
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;
NSError *error = nil;
if (![self.fetchedResultsController performFetch:&error]) {
// Replace this implementation with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
if (self.view.window){
if([__fetchedResultsController fetchedObjects].count < 10){
if(self.segmentedControl.selectedSegmentIndex == 1 || [self.isEuro boolValue]){
//Ricco[self performSelector:@selector(getMoreStories)];
//Ricco[SVProgressHUD showWithStatus:@"Loading Rumours..." maskType:SVProgressHUDMaskTypeGradient];
}
}
if([__fetchedResultsController fetchedObjects].count == 0){
if([self.isPopular boolValue])
[self popularRefresh];
if([self.isVirals boolValue])
[self viralsRefresh];
}
}
return __fetchedResultsController;
}