实用程序模板:如何从翻转视图刷新UIPickerView

时间:2012-07-10 17:55:50

标签: iphone objective-c ios

我正在使用带有核心数据的实用程序应用程序模板。在侧视图中,用户可以在主视图上添加项目和这些项目品牌和模型提供UIPickerView。

当用户添加项目时,除非她或他关闭应用程序,否则此添加的项目不会出现在选取行标题中。

如何在不关闭应用的情况下加载此标题? 感谢

编辑以添加代码:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    //retrieving data from iGear.xcdatamodeld
    iGearAppDelegate *iGearDelegate = [[UIApplication sharedApplication]delegate];
    NSManagedObjectContext *context = [iGearDelegate managedObjectContext];
    NSError *error;

    if (managedObjectContext !=nil) {
        if ([managedObjectContext hasChanges] && [managedObjectContext save:&error]) {
            //NSLog(@"Retrieving: unresolved error %@, %@",error, [error userInfo]);
            abort();
         }
    }

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc]init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Cogset"     inManagedObjectContext:context];

    [fetchRequest setEntity:entity];
    fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];

//#pragma mark UIPickerView

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
    {
        return 1;
    }
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent: (NSInteger)component
 {
    return [fetchedObjects count];
 }

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    if (component == 0) 
    {
        cogset = [fetchedObjects objectAtIndex:row];
        return [NSString stringWithFormat:@"%@ %@",cogset.brand,cogset.model];
    }
    return @"";
}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    cassette = [fetchedObjects objectAtIndex:[_chooseCogsetPickerView  selectedRowInComponent:0]];
}

1 个答案:

答案 0 :(得分:0)

您应该为UIPickerView实现UIPickerViewDelegate

然后,使用此委托功能填充选择器视图:

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component ]
{
 return someValue;
}

如果您发布一些当前正在发生的实际代码,我可以尝试更具体地帮助您。