Cocoa touch provides a class for notifying users to wait for the process to complete:
1. uiactivityindicatorview: provides a circle to notify the user of waiting. No specific information is provided.
2. uiprogressview: displays the progress bar and quantifies the workload (time)
3. uiprogresshud: the job is not quantified, but the job status or progress is displayed. Note that this class is not in the standard SDK
For the above three types, useCodeTo demonstrate the application
1 \
# Define Indicator_view 999
@ InterfaceHellocontroller: uiviewcontroller
{
Bool progressshowing;
}
@ End
@ ImplementationHellocontroller
-(Void) Invalid maction
{
Uiactivityindicatorview*Activityindicator=(Uiactivityindicatorview*) [Self. View viewwithtag: indicator_view];
If(Progressshowing) [activityindicator stopanimating];Else[Activityindicator startanimating];
Progressshowing=!Progressshowing;
}
-(ID) Init
{
If(Self=[Super init]) self. Title=@"Hello World";
ReturnSelf;
}
-(Void) Loadview
{
Uiview*Contentview=[[Uiview alloc] initwithframe: [[uiscreen mainscreen] applicationframe];
Self. View=Contentview;
Contentview. backgroundcolor=[Uicolor whitecolor];
[Contentview release];
Self. navigationitem. rightbarbuttonitem=[[Uibarbuttonitem alloc]
Initwithtitle:@"Do it"
Style: uibarbuttonitemstyleplain
Target: Self
Action: @ selector (partition maction)] autorelease];
// Add the progress indicator but do not start it
progressshowing = NO;
uiactivityindicatorview * activityindicator = [[uiactivityindicatorview alloc] initwithframe: cgrectmake ( 0.0f , 0.0f , 32.0f , 32.0f )];
[activityindicator setcenter: cgpointmake ( 160.0f , 208.0f )];
[activityindicator setactivityindicatorviewstyle: uiactivityindicatorviewstylegray];
activityindicator. tag = indicator_view;
[contentview addsubview: activityindicator];
[activityindicator release];
}< br> @ end
The key points in the Code are: progressshowing and activityindicator. Tag = indicator_view; [contentview addsubview: activityindicator];
2 \
Extended uiactionsheet Function
@ Interface Uiactionsheet (extended)
- ( Void ) Setnumberofrows: (nsinteger) rows;
- ( Void ) Setmessage: (nsstring * ) Message;
@ End
// Timer event processing
- ( Void ) Incrementbar :( ID ) Timer
{
Amountdone + = 1.0f ;
Uiprogressview * Progbar = (Uiprogressview * ) [Self. basesheet viewwithtag: progress_bar];
[Progbar setprogress: (amountdone / 20.0 )];
If (Amountdone > 20.0 )
{
[Self. basesheet dismisswithclickedbuttonindex: 0 Animated: Yes];
[Timer invalidate];
}
}
// Display the view
- ( Void ) Presentsheet
{
If(!Self. basesheet ){
Basesheet=[[Uiactionsheet alloc]
Initwithtitle:@"Please wait"
Delegate: Self
Cancelbuttontitle: Nil
Destructivebuttontitle: Nil
Otherbuttontitles: Nil];
[Basesheet setnumberofrows:5];
[Basesheet setmessage:@"Updating internal databases"];
Uiprogressview*Progbar=[[Uiprogressview alloc] initwithframe: cgrectmake (50366f,70.0f,220366f,90.0f)];
Progbar. Tag=Progress_bar;
[Progbar setprogressviewstyle: uiprogressviewstyledefault];
[Basesheet addsubview: progbar];
[Progbar release];
}
Uiprogressview*Progbar=(Uiprogressview*) [Self. View viewwithtag: progress_bar];
[Progbar setprogress :( amountdone=0.0f)];
[Nstimer scheduledtimerwithtimeinterval:0.5Target: Self selector: @ selector (incrementbar :) userinfo: Nil repeats: Yes];
[Basesheet showinview: Self. View];
}
Release Functions
- ( Void ) Dealloc
{
// Release basesheet
If (Self. basesheet) [self. basesheet release];
[Super dealloc];
}
In this example, Timer regularly updates the progress bar status.
Uiactionsheet is used to display the progress status.
Running on xcode4 does not have the expected effect ~~ In the cup, see what to do later
In addition,
[Basesheet setnumberofrows: 5];
[Basesheet setmessage: @ "Updating internal databases"];
Failed to execute the expected results ~~~
3 \
Declare an existing class
- ( Void ) Dealloc
{
// Release basesheet
If (Self. basesheet) [self. basesheet release];
[Super dealloc];
}
Some code in the Controller
- ( Void ) Killhud :( ID ) Ahud
{
[Ahud show: No];
[Ahud release];
}
- ( Void ) Presentsheet
{
ID HUD = [[Uiprogresshud alloc] initwithwindow: [self. View superview];
[HUD settext: @" Downloading file. Please wait. " ];
[HUD show: Yes];
[Self defined mselector: @ selector (killhud :) withobject: HUD afterdelay:5.0];
}
Class learning:
Uiactivityindicatorview class
The uiactivityindicatorview class creates and manages an indicator showing the indeterminate progress of a task.
The uiactivityindicatorview class creates and manages the indicator, which is used to display the progress of the current task.
Method:
-Initwithactivityindicatorstyle:
-Startanimating
-Stopanimating
-Isanimating
Attribute:
Hideswhenstopped indicates whether the view is hidden after the animation ends.
Activityindicatorviewstyle indicator view Style
Uiprogressview class
Method:
-Initwithprogressviewstyle:
Attribute:
SS: progress, float, 0.0-1.0
Progressviewstyle: progress view Style
Undisclosed:
Uiprogresshud class
UiactionsheetSome functions:
-(Void) setnumberofrows: (nsinteger) rows;
-(Void) setmessage: (nsstring *) message;