English 中文(简体)
关于FetchRequest的声明
原标题:If statement on FetchRequest

How do I make it so I only fetch results with the indicator == 1. (I have the indicator hooked up to a UISwitch on another view). so I want a table of titles, but only if the indicator is 1.

-(void)reload
{
    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Event" inManagedObjectContext:managedObjectContext];
    [request setEntity:entity];

    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"Title" ascending:YES]; 
    NSSortDescriptor *sortDescriptor2 = [[NSSortDescriptor alloc]initWithKey:@"indicator" ascending:YES];
    NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, sortDescriptor2, nil]; 
    [request setSortDescriptors:sortDescriptors];
    [sortDescriptors release]; 
    [sortDescriptor release];

    NSError *error = nil; 
    NSMutableArray *mutableFetchResults = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy]; 
    if (mutableFetchResults == nil) {
        // Handle the error.
    }

    [self setList:mutableFetchResults]; 
    [mutableFetchResults release]; 
    [request release];
}
最佳回答

根据你的要求增加:

[request setPredicate:[NSPredicate predicateWithFormat:@"indicator == 1"]];

这只造成它打算返回的事件。 我也从描述中删除你的描述。 在计算指标的关键值时,没有任何意义。

问题回答

暂无回答




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签