Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 实用程序应用程序模板:如何从flipside视图刷新UIPickerView_Iphone_Objective C_Ios - Fatal编程技术网

Iphone 实用程序应用程序模板:如何从flipside视图刷新UIPickerView

Iphone 实用程序应用程序模板:如何从flipside视图刷新UIPickerView,iphone,objective-c,ios,Iphone,Objective C,Ios,我正在使用具有核心数据的实用程序应用程序模板。在flipside视图中,用户可以添加项目,这些项目的品牌和型号在主视图上提供UIPickerView 当用户添加项目时,除非她或他关闭应用程序,否则添加的项目不会出现在选择器行标题中 如何在不关闭应用程序的情况下加载此标题? 谢谢 编辑以添加代码: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view,

我正在使用具有核心数据的实用程序应用程序模板。在flipside视图中,用户可以添加项目,这些项目的品牌和型号在主视图上提供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]];
}

您应该为UIPickerView实现一个
UIPickerViewDeleteGate

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

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

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

PickerView上的标题显示正确,但情况是,我需要刷新主视图,或者至少使用“-(void)viewwillappeard”方法。如果应用程序在iPhone上运行,没有问题,但在iPad上,用户在popover上添加数据。也许我应该把这件popover换成模态视图。。。