iphone UIProgressView 进度使用例子

iphone UIProgressView 进度使用例子


待实现功能:打开首页面时,应用从服务器下载数据,首页上的进度条显示数据下载的进度:


步骤一:在xib 中 添加 UIProgressView,UILabel两个控件;

步骤二:编码;

接口:

@interface BetaTownViewController : UIViewController
{

    IBOutlet UIProgressView *progressView;//进度条控件
    IBOutlet UILabel *lblMessage;//用于进度显示
    float progress;//存放进度值
    NSString * progressMsg;//存放进度信息
}

@property (nonatomic,retain) UIProgressView *progressView;
@property (nonatomic,retain) NSString *progressMsg;
@property (nonatomic) float progress;

实现:


#import "BetaTownViewController.h"


@implementation BetaTownViewController

@synthesize progressView;
@synthesize progress;
@synthesize progressMsg;


- (void)didReceiveMemoryWarning{
    [super didReceiveMemoryWarning];
}

#pragma mark - View lifecycle

- (void)viewDidLoad{
    [super viewDidLoad];
}

- (void)viewDidUnload{
    [super viewDidUnload];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}

-(void) updateProgress{
    [progressView setProgress:progress];
    [lblMessage setText:progressMsg];
}


-(void) initDATA{
    
    progress =0.1;
    progressMsg = @"开始调用方法1,请稍后...";
    [self performSelectorOnMainThread:@selector(updateProgress) withObject:nil waitUntilDone:NO];
	//调用方法1
    
    progress =0.3;
    progressMsg = @"开始调用方法2,请稍后...";
    [self performSelectorOnMainThread:@selector(updateProgress) withObject:nil waitUntilDone:NO];
	//调用方法2
    
    progress =0.7;
    progressMsg = @"开始调用方法3,请稍后...";
    [self performSelectorOnMainThread:@selector(updateProgress) withObject:nil waitUntilDone:NO];
	//调用方法3
    
    progress =1.0;
    progressMsg = @"方法调用完毕";
    [self performSelectorOnMainThread:@selector(updateProgress) withObject:nil waitUntilDone:NO];
    
}

- (void)viewDidAppear:(BOOL)animated{
    //开启线程,进行下载数据
    [NSThread detachNewThreadSelector:@selector(initDATA) toTarget:self withObject:nil];
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated{
	[super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated{
	[super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
	return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end


 

我把部分代码删除掉了,但思路是这样的,要启用一下线程来更新进度值;

最后还是希望大家在写技术贴时,不要copy来,copy去,否则浪费其他人的时间。



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值