Three20软件引擎之TabBar与下拉列表访问数据与刷新(五)

Three20软件引擎之TabBar与下拉列表访问数据与刷新




MOMO一直在使用新浪微博,对围脖中拖动下拉刷新的控件比较感兴趣,顺便求个粉,哇咔咔,点击博客 页左侧记得粉我喔。今天制作了一个简单的小例子,好东西一定要和大家分享哦。如下图所示,本节我们实现的是目标:1.在屏幕下方添加TabBar控件,选择不同的控件后刷新不同的资源。2.在屏幕中向下拖动界面时在顶端出现刷新的视图,手放开后开始访问 络下载数据。本节我们访问的 址是Google的Logo图片地址,首次刷新时将访问下载地址,然后将图片资源缓存至本地,再次刷新时先查看缓存中是否有这张图片,如果有则不继续访问下载图片。下图中还有一个小瑕疵,就是顶端视图中刷新的现实内容位英文,不过不要紧后面我会告诉大家如何修改这些文字成中文。



通过如下方法即可在缓存中获取该对象, 值得注意的时url并不是上图中对应的资源名称,而是下载图片时的地址。

TTURLCache* cacheStore = [TTURLCache sharedCache]; UIImage * image = [cacheStore imageForURL:_url fromDisk:NO];
CustomDaragRefesh.h

#import <Three20/Three20.h> @interface CustomDaragRefesh : TTTableViewDragRefreshDelegate { } @end

CustomDaragRefesh.m

用于监听下拉列表所有的事件。

#import “CustomDaragRefesh.h” @implementation CustomDaragRefesh – (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@”点击刷新视图时”); } – (void)scrollViewDidScroll:(UIScrollView*)scrollView { [super scrollViewDidScroll:scrollView]; NSLog(@”拖动刷新视图时”); } – (void)scrollViewDidEndDragging:(UIScrollView*)scrollView willDecelerate:(BOOL)decelerate { [super scrollViewDidEndDragging:scrollView willDecelerate:decelerate]; NSLog(@”拖动刷新视图松手时”); } – (void)modelDidStartLoad:(id<TTModel>)model { NSLog(@”开始下载时”); } – (void)modelDidFinishLoad:(id<TTModel>)model { NSLog(@”下载结束时”); } – (void)model:(id<TTModel>)model didFailLoadWithError:(NSError*)error { NSLog(@”下载失败的错误%@”, error); } @end

最后我们学习文章开头中提到的,如何修改刷新文字。我觉得这里直接修改源码就可以,我查看了源码,感觉这里写的非常不灵活。刷新的文字写在TTTabHeaderDragRefreshView中。如下图所示,刷新的文字已经修改成中文。最后我们在来学习一下Three20的运行机制,编译程序时Three20会把自身所有的.m文件封装成.a文件。我们修改了它的源码,编译时three20会重新生成新的.a文件,所以我们无法进行调试Three20中的源码。

Three20软件引擎之TabBar与下拉列表访问数据与刷新(五)


修改过的代码

@implementation TTTableHeaderDragRefreshView /// /// #pragma mark – #pragma mark Private /// – (void)showActivity:(BOOL)shouldShow animated:(BOOL)animated { if (shouldShow) { [_activityView startAnimating]; } else { [_activityView stopAnimating]; } [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:(animated ttkDefaultFastTransitionDuration : 0.0)]; _arrowImage.alpha = (shouldShow 0.0 : 1.0); [UIView commitAnimations]; } /// – (void)setImageFlipped:(BOOL)flipped { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:ttkDefaultFastTransitionDuration]; [_arrowImage layer].transform = (flipped CATransform3DMakeRotation(M_PI * 2, 0.0f, 0.0f, 1.0f) : CATransform3DMakeRotation(M_PI, 0.0f, 0.0f, 1.0f)); [UIView commitAnimations]; } /// /// #pragma mark – #pragma mark NSObject /// – (id)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { self.autoresizingMask = UIViewAutoresizingFlexibleWidth; _lastUpdatedLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, frame.size.height – 30.0f, frame.size.width, 20.0f)]; _lastUpdatedLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin; _lastUpdatedLabel.font = TTSTYLEVAR(tableRefreshHeaderLastUpdatedFont); _lastUpdatedLabel.textColor = TTSTYLEVAR(tableRefreshHeaderTextColor); _lastUpdatedLabel.shadowColor = TTSTYLEVAR(tableRefreshHeaderTextShadowColor); _lastUpdatedLabel.shadowOffset = TTSTYLEVAR(tableRefreshHeaderTextShadowOffset); _lastUpdatedLabel.backgroundColor = [UIColor clearColor]; _lastUpdatedLabel.textAlignment = UITextAlignmentCenter; [self addSubview:_lastUpdatedLabel]; _statusLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, frame.size.height – 48.0f, frame.size.width, 20.0f )]; _statusLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin; _statusLabel.font = TTSTYLEVAR(tableRefreshHeaderStatusFont); _statusLabel.textColor = TTSTYLEVAR(tableRefreshHeaderTextColor); _statusLabel.shadowColor = TTSTYLEVAR(tableRefreshHeaderTextShadowColor); _statusLabel.shadowOffset = TTSTYLEVAR(tableRefreshHeaderTextShadowOffset); _statusLabel.backgroundColor = [UIColor clearColor]; _statusLabel.textAlignment = UITextAlignmentCenter; [self setStatus:TTTableHeaderDragRefreshPullToReload]; [self addSubview:_statusLabel]; UIImage* arrowImage = TTSTYLEVAR(tableRefreshHeaderArrowImage); _arrowImage = [[UIImageView alloc] initWithFrame:CGRectMake(25.0f, frame.size.height – 60.0f, arrowImage.size.width, arrowImage.size.height)]; _arrowImage.image = arrowImage; [_arrowImage layer].transform = CATransform3DMakeRotation(M_PI, 0.0f, 0.0f, 1.0f); [self addSubview:_arrowImage]; _activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; _activityView.frame = CGRectMake( 30.0f, frame.size.height – 38.0f, 20.0f, 20.0f ); _activityView.hidesWhenStopped = YES; [self addSubview:_activityView]; } return self; } /// – (void)dealloc { TT_RELEASE_SAFELY(_activityView); TT_RELEASE_SAFELY(_statusLabel); TT_RELEASE_SAFELY(_arrowImage); TT_RELEASE_SAFELY(_lastUpdatedLabel); TT_RELEASE_SAFELY(_lastUpdatedDate); [super dealloc]; } /// /// #pragma mark – #pragma mark Public /// – (void)setUpdateDate:(NSDate*)newDate { if (newDate) { if (_lastUpdatedDate != newDate) { [_lastUpdatedDate release]; } _lastUpdatedDate = [newDate retain]; NSDateFormatter* formatter = [[NSDateFormatter alloc] init]; [formatter setDateStyle:NSDateFormatterShortStyle]; [formatter setTimeStyle:NSDateFormatterShortStyle]; _lastUpdatedLabel.text = [NSString stringWithFormat: TTLocalizedString(@”最后更新: %@”, @”The last time the table view was updated.”), [formatter stringFromDate:_lastUpdatedDate]]; [formatter release]; } else { _lastUpdatedDate = nil; _lastUpdatedLabel.text = TTLocalizedString(@”Last updated: never”, @”The table view has never been updated”); } } /// – (void)setCurrentDate { [self setUpdateDate:[NSDate date]]; } /// – (void)setStatus:(TTTableHeaderDragRefreshStatus)status { switch (status) { case TTTableHeaderDragRefreshReleaseToReload: { [self showActivity:NO animated:NO]; [self setImageFlipped:YES]; _statusLabel.text = TTLocalizedString(@”松开即可刷新…”, @”Release the table view to update the contents.”); break; } case TTTableHeaderDragRefreshPullToReload: { [self showActivity:NO animated:NO]; [self setImageFlipped:NO]; _statusLabel.text = TTLocalizedString(@”下拉可以刷新…”, @”Drag the table view down to update the contents.”); break; } case TTTableHeaderDragRefreshLoading: { [self showActivity:YES animated:YES]; [self setImageFlipped:NO]; _statusLabel.text = TTLocalizedString(@”加载中…”, @”Updating the contents of a table view.”); break; } default: { break; } } } @end


最后欢迎各位盆友可以和MOMO一起讨论Three20软件开发,如果你觉得看得不清楚,MOMO附带上本章的源码下载,希望大家可以一起学习 哈哈~。哇咔咔~ MOMO愿和 大家好好学习,大家一起进步哈~!!!


下载地址:http://download.csdn.net/detail/xys289187120/4183984
(下载后必需搭建three20环境成功后才能运行~ 因为three20为引用加载,所以程序路径都是我本机的请见谅!或者你可可以将你的Three20路径修改的和我一样就可以直接运行啦,我的路径是:User (用户) -> Share(共享)->Three20)。






相关资源:锁屏 自动锁屏 定时锁屏 注销软件

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2012年2月25日
下一篇 2012年2月25日

相关推荐