简体   繁体   English

使用UIProgressView作为目标的进度指示器

[英]Using UIProgressView as a Progress indicator for goals

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. 总体目标:使用UIProgressView作为指标的“不同类型”。
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"). 详细信息:当用户“完成”“目标”时(通过在单独的UIViewController按下名为“ complete”的UIButton,我们将其称为“ View Controller 1”),我希望它在第二个UIViewController更新UIProgressView(将此称为“ View Controller 2”。 There are several UIProgressViews in View Controller 2, each representing the # of goals in a category 'completed'. View Controller 2中有多个UIProgressViews ,每个UIProgressViews表示“已完成”类别中的目标数量。 So I'd like to have a void method in View Controller 2 like this: 所以我在一个void方法View Controller 2所示:

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

在此处输入图片说明

Thank you in advance for your help. 预先感谢您的帮助。

What you can do is on Touching of Button in VIEW CONTROLLER 1 you store the Value of the goals completed in a particular category. 您可以做的就是在“视图控制器1”中的“触摸按钮”上存储在特定类别中完成的目标的价值。 Example Code for View Controller 1: View Controller 1的示例代码:

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

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

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

Now in View Controller 2 what you should do is in ViewDidLoad method or in ViewWillAppear method you should get the value you stored in NSUserDefaults and update it in progress bar value 现在,在View Controller 2中,您应该在ViewDidLoad方法或ViewWillAppear方法中进行操作,您应该获取存储在NSUserDefaults中的值并在进度栏中更新它的值

-(void)viewDidLoad
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    int val = [defaults valueForKey:category];
    categoryOneProgressBar.progress = val;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM