0

I've tried figuring this out on my own, and am completely clueless as to how to accomplish it. Essentially what I'm trying to do is this:

The Overall Goal: Use the UIProgressView as a "different type" of indicator than what it's meant for.
Details: When a user 'completes' a 'goal' (by pressing a UIButton named "complete" in a separate UIViewController, let's call this one "View Controller 1") I'd like it to update a UIProgressView in a second UIViewController (call this one "View Controller 2"). There are several UIProgressViews in View Controller 2, each representing the # of goals in a category 'completed'. So I'd like to have a void method in View Controller 2 like this:

 (void)progressMade:(NSString *)category
{
   categoryOneProgressView.progress += 1/8 ;
   //this would be called from View Controller 1, after the "complete" button was pressed.
}

enter image description here

Thank you in advance for your help.

4

1 回答 1

0

您可以做的是在 VIEW CONTROLLER 1 中触摸按钮,您可以将已完成目标的值存储在特定类别中。视图控制器 1 的示例代码:

-(void)methodTriggeredOnCompleted:(NSString *)category
{
    //Do you calculation for progress of a category 

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    [defaults setValue:saveProgressValue forKey:category];
    [defaults synchronize];
}

现在在 View Controller 2 中,您应该在 ViewDidLoad 方法或 ViewWillAppear 方法中获取存储在 NSUserDefaults 中的值并在进度条值中更新它

-(void)viewDidLoad
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    int val = [defaults valueForKey:category];
    categoryOneProgressBar.progress = val;
}
于 2012-09-10T15:57:31.840 回答