发布于 2014-10-29 09:18:56 | 847 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

iOS苹果移动操作系统

苹果iOS是由苹果公司开发的移动操作系统。苹果公司最早于2007年1月9日的Macworld大会上公布这个系统,最初是设计给iPhone使用的,后来陆续套用到iPod touch、iPad以及Apple TV等产品上。


本文为大家讲解的是ios开发中实现UI下拉刷新功能,感兴趣的同学参考下。

由于表应用有两个UI设计模式: 分页模式、下拉刷新模式。

其中下拉刷新被广泛应用(新浪微博,QQ)

这里吐槽一下QQ的墨迹,其实PC桌面的应用还好,及时的扁平化。但是IOS这么大的市场,但是现在都IOS8了,为什么还在用IOS6的下拉刷新的“胶皮糖”UI样式。

IOS6以后增加了一个UIRefreshControl的下拉刷新类,目前这个类只能应用于表视图界面。

在Xcode6中,还没有在故事版中增加下拉拖拽,类似label之类的控件。所以布局什么的不用太多考虑。

代码部分可重用,目前就当作一个库来用吧。

 

 

H文件:

#import <UIKit/UIKit.h>  

@interface TableViewController : UITableViewController  

@property (nonatomic, strong) NSMutableArray * Logs;  

@end 

M文件:

#import "ViewController.h"  
 
@interface TableViewController ()  
 
@end  
 
@implementation TableViewController  
 
- (void)viewDidLoad {  
    [super viewDidLoad];  
      
    // 初始化变量和时间  
    self.Logs = [[NSMutableArray alloc] init];  
    NSDate *date = [[NSDate alloc] init];  
    [self.Logs addObject:date];  
      
    // 初始化UIRefreshControl  
    // rc为该控件的一个指针,只能用于表视图界面  
    // 关于布局问题可以不用考虑,关于UITableViewController会将其自动放置于表视图中  
      
    UIRefreshControl *rc = [[UIRefreshControl alloc] init];  
    rc.attributedTitle = [[NSAttributedString alloc]initWithString:@"下拉刷新"];  
    // 一定要注意selector里面的拼写检查  
    [rc addTarget:self action:@selector(refreshTableView) forControlEvents:UIControlEventValueChanged];  
    self.refreshControl = rc;  
}  
 
- (void)didReceiveMemoryWarning {  
    [super didReceiveMemoryWarning];  
    // Dispose of any resources that can be recreated.  
}  
 
- (void) refreshTableView  
{  
    if (self.refreshControl.refreshing) {// 判断是否处于刷新状态  
        self.refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString: @"加载中..."];  
        // 添加新的模拟器  
        NSDate *date = [[NSDate alloc] init];  
        // 模拟请求完成以后,回调方法callBackMethod  
        [self performSelector:@selector(callBackMethod:) withObject:date afterDelay: 3];  
    }  
      
}  
 
- (void) callBackMethod:(id) obj  
{  
    [self.refreshControl endRefreshing];    // 停止下拉刷新控件,回到初始状态  
    self.refreshControl.attributedTitle =[[NSAttributedString alloc]initWithString:@"下拉刷新"];   // 文本变回来  
    [self.Logs addObject:(NSDate *)obj];  
      
    [self.tableView reloadData];  
}  
 
#pragma mark --- UITableViewDataSource代码  
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView  
{  
    return 1;  
}  
 
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section  
{  
    return [self.Logs count];  
}  
 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath  
{  
    // 这可以说是Cell部分最重要的代码段了  
    // 定义Cell,然后判断cellIdentifier是否重用  
    static NSString *CellIdentifier = @"Cell";  
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];  
    if (cell == nil) {  
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier: CellIdentifier];  
    }  
      
    // 然后获取时间  
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];  
    [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];  
      
    // 然后更新cell  
    cell.textLabel.text = [dateFormat stringFromDate:[self.Logs objectAtIndex:[indexPath row]]];  
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;  
      
    return cell;  
}  
 
 
@end



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务