<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      [Cocoa]在工程中使用Three20庫(kù):下拉刷新 tableview

      [Cocoa]在工程中使用Three20庫(kù):下拉刷新 tableview

      本文遵循“署名-非商業(yè)用途-保持一致”創(chuàng)作公用協(xié)議

      Three20 是 facebook 開(kāi)源的一款功能齊全又強(qiáng)大的庫(kù),覆蓋 UI,network,JSON/XML解析等。其 github 倉(cāng)庫(kù)在這里:https://github.com/facebook/three20 ,這個(gè)頁(yè)面也有如何在工程中添加 three20 庫(kù)的介紹,不過(guò)在 Lion 版下以及 xcode 4.2 下有些許不同,英文好的同學(xué)可以參看原文?,F(xiàn)整理如下:

      1,新建一個(gè)名為 Three20Demo 的 Empty Application;

       

      2,在這頁(yè)面上下載 three20 zip源代碼工程;解壓到與 Three20Demo 項(xiàng)目平級(jí)的目錄下;

       

      3,拖拽 "three20/src/Three20/" 目錄下的 Three20.xcodeproj 到 Three20Demo 工程中,如下圖。


      4,選中  Three20Demo 的 target ,在 Build Phases 的 Link Binary With Libraries 中添加 three20 的靜態(tài)庫(kù)。如下圖:

       

      5,拖拽 "three20/src" 下面的Three20.bundle 到 Three20Demo 工程下,在彈出的對(duì)話框中不要選擇 Copy Item into 那個(gè)選項(xiàng),選擇第二個(gè) Create groups for any added folders。

       


      6,類似第4步,向 three20Demo 中添加 QuartzCore.framework 。

       

      7,在工程的 Build settings 中向 "Other Linker Flags" 添加 -ObjC 和 -all_load 兩項(xiàng)。

       

      8,編譯運(yùn)行工程,然后至你自己用戶的 Library 目錄下拷貝 three20 頭文件至你的項(xiàng)目目錄下。(Lion版本無(wú)法查看隱藏目錄,command + shift + G ,然后輸入 ~/Library,就可以找到隱藏的library)。 three20 目錄位于:

      /Users/yourname/Library/Developer/Xcode/DerivedData/Three320Demo-XXXXXX/Build/Products/three20

       

      9,在工程的 Build settings 中向 "Header Search Paths" 添加 three20,并選中 Recursive 選項(xiàng)。

       

      10, 至此,所有的配置工作完成,你可以在工程中使用包含如下頭文件:#import <Three20/Three20.h> 來(lái)使用 Three20 庫(kù)。

       

      Three20 解壓的包里面有個(gè) sample 目錄,里面展示了大部分 api 的使用,可以運(yùn)行看看。

       

      下面我將演示如何使用 TTTableViewController。向工程中添加類 KSDataSource 這個(gè)類作為 TTTableView 的 datasource。

      KSDataSource.h

      //
      // DataSource.h
      // Three320Demo
      //
      // Created by LuoZhaohui on 12/31/11.
      // Copyright (c) 2011 kesalin@gmail.com. All rights reserved.
      //

      #import <Three20/Three20.h>

      // Model
      //
      @interface KSMockModel : NSObject <TTModel>
      {
      @private
      NSArray * allNames;
      NSMutableArray * names;
      NSMutableArray * delegates;

      NSTimer* fakeSearchTimer;
      NSTimeInterval fakeSearchDuration;
      NSTimer* fakeLoadingTimer;
      NSTimeInterval fakeLoadingDuration;
      }

      @property(nonatomic,retain) NSArray * names;
      @property(nonatomic) NSTimeInterval fakeSearchDuration;
      @property(nonatomic) NSTimeInterval fakeLoadingDuration;

      + (NSMutableArray *) fakeNames;

      - (id)initWithNames:(NSArray *)names;
      - (void)search:(NSString *)text;

      @end

      // DataSource
      //
      @interface KSDataSource : TTSectionedDataSource
      {
      KSMockModel * mockModel;
      }

      @property(nonatomic,readonly) KSMockModel * mockModel;

      @end

      KSDateSource.m

      //
      // DataSource.m
      // Three320Demo
      //
      // Created by LuoZhaohui on 12/31/11.
      // Copyright (c) 2011 kesalin@gmail.com. All rights reserved.
      //

      #import "KSDataSource.h"

      @interface KSMockModel ()

      - (void) loadNames;

      @end

      @implementation KSMockModel

      @synthesize names;
      @synthesize fakeSearchDuration, fakeLoadingDuration;

      + (NSMutableArray *) fakeNames
      {
      return [NSMutableArray arrayWithObjects:
      @"Hector Lewis",
      @"Juanita Fredrick",
      @"Richard Raymond",
      @"Marcia Myer",
      @"Shannon Mahoney",
      @"James Steiner",
      @"Daniel Lloyd",
      @"Fredrick Hutchins",
      @"Tracey Smith",
      @"Brandon Rutherford",
      @"Megan Lopez",
      @"Jean Trujillo",
      @"Franklin Diamond",
      @"Mildred Jacobsen",
      @"Sandra Adams",
      @"Debra Pugliese",
      @"Cynthia Hall",
      @"Joshua Hicks",
      @"Lorenzo Evatt",
      @"Erica Dozier",
      @"Barbara Lazarus",
      @"Joye Hocker",
      @"Henry Arana",
      @"Glen Cabrales",
      nil];
      }

      - (id) initWithNames:(NSArray *)nameArray
      {
      self = [super init];
      if (self)
      {
      delegates = nil;
      allNames = [nameArray copy];
      names = nil;
      fakeSearchTimer = nil;
      fakeSearchDuration = 0;
      }

      return self;
      }

      - (void) dealloc
      {
      TT_INVALIDATE_TIMER(fakeSearchTimer);
      TT_INVALIDATE_TIMER(fakeLoadingTimer)
      TT_RELEASE_SAFELY(allNames);
      TT_RELEASE_SAFELY(names);
      TT_RELEASE_SAFELY(delegates);

      [super dealloc];
      }

      // TTModel
      //
      - (NSMutableArray*) delegates
      {
      if (!delegates)
      {
      delegates = TTCreateNonRetainingArray();
      }

      return delegates;
      }

      - (BOOL)isLoadingMore
      {
      return NO;
      }

      - (BOOL)isOutdated
      {
      return NO;
      }

      - (BOOL)isLoaded
      {
      return !!names;
      }

      - (BOOL)isLoading
      {
      return !!fakeSearchTimer || !!fakeLoadingTimer;
      }

      - (BOOL)isEmpty
      {
      return !names.count;
      }

      - (void)fakeLoadingReady
      {
      fakeLoadingTimer = nil;

      [self loadNames];

      [delegates perform:@selector(modelDidFinishLoad:) withObject:self];
      }

      - (void)load:(TTURLRequestCachePolicy)cachePolicy more:(BOOL)more
      {
      [delegates perform:@selector(modelDidStartLoad:) withObject:self];

      if (fakeLoadingDuration)
      {
      TT_INVALIDATE_TIMER(fakeLoadingTimer);
      fakeLoadingTimer = [NSTimer scheduledTimerWithTimeInterval:fakeLoadingDuration
      target:self
      selector:@selector(fakeLoadingReady)
      userInfo:nil
      repeats:NO];
      [delegates perform:@selector(modelDidStartLoad:) withObject:self];
      }
      else
      {
      [self loadNames];

      [delegates perform:@selector(modelDidFinishLoad:) withObject:self];
      }
      }

      - (void)invalidate:(BOOL)erase
      {
      }

      - (void)cancel
      {
      if (fakeSearchTimer)
      {
      TT_INVALIDATE_TIMER(fakeSearchTimer);
      [delegates perform:@selector(modelDidCancelLoad:) withObject:self];
      }
      else if (fakeLoadingTimer)
      {
      TT_INVALIDATE_TIMER(fakeLoadingTimer);
      [delegates perform:@selector(modelDidCancelLoad:) withObject:self];
      }
      }

      // public
      //
      - (void)loadNames
      {
      TT_RELEASE_SAFELY(names);
      names = [allNames mutableCopy];
      }

      - (void)search:(NSString *)text
      {
      [self cancel];

      TT_RELEASE_SAFELY(names);
      if (text.length)
      {
      if (fakeSearchDuration)
      {
      TT_INVALIDATE_TIMER(fakeSearchTimer);
      fakeSearchTimer = [NSTimer scheduledTimerWithTimeInterval:fakeSearchDuration
      target:self
      selector:@selector(fakeSearchReady:)
      userInfo:text
      repeats:NO];
      [delegates perform:@selector(modelDidStartLoad:) withObject:self];
      }
      else
      {
      [self fakeSearch:text];
      [delegates perform:@selector(modelDidFinishLoad:) withObject:self];
      }
      }
      else
      {
      [delegates perform:@selector(modelDidChange:) withObject:self];
      }
      }

      @end

      //
      // DataSource
      //
      @implementation KSDataSource

      @synthesize mockModel;

      - (id) init
      {
      self = [super init];
      if (self)
      {
      mockModel = [[KSMockModel alloc] initWithNames:[KSMockModel fakeNames]];
      self.model = mockModel;
      }
      return self;
      }

      - (void)dealloc
      {
      TT_RELEASE_SAFELY(mockModel);

      [super dealloc];
      }

      // UITableViewDataSource
      //
      - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
      {
      return [TTTableViewDataSource lettersForSectionsWithSearch:YES summary:NO];
      }

      - (void) tableViewDidLoadModel:(UITableView *)tableView
      {
      self.items = [NSMutableArray array];
      self.sections = [NSMutableArray array];

      NSMutableDictionary * groups = [NSMutableDictionary dictionary];
      for (NSString * name in mockModel.names)
      {
      NSString * letter = [NSString stringWithFormat:@"%C", [name characterAtIndex:0]];
      NSMutableArray * section = [groups objectForKey:letter];
      if (!section)
      {
      section = [NSMutableArray array];
      [groups setObject:section forKey:letter];
      }

      TTTableItem * item = [TTTableTextItem itemWithText:name URL:nil];
      [section addObject:item];
      }

      NSArray * letters = [groups.allKeys sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
      for (NSString * letter in letters)
      {
      NSArray * items = [groups objectForKey:letter];
      [_sections addObject:letter];
      [_items addObject:items];
      }
      }

      - (id<TTModel>) model
      {
      return mockModel;
      }

      @end


      然后修改 KSViewController.h 為:

      #import <Three20/Three20.h>

      @interface KSViewController : TTTableViewController <TTTableViewDataSource, TTTableViewDelegate>

      @end


      修改 KSViewController.m 為:

      //
      // KSViewController.m
      // Three320Demo
      //
      // Created by LuoZhaohui on 12/31/11.
      // Copyright (c) 2011 kesalin@gmail.com. All rights reserved.
      //

      #import "KSViewController.h"
      #import "KSDataSource.h"

      @implementation KSViewController

      // TTTableView
      //
      - (void) createModel
      {
      KSDataSource *dataSource = [[KSDataSource alloc] init];
      dataSource.mockModel.fakeLoadingDuration = 2.0;
      dataSource.mockModel.fakeSearchDuration = 2.0;

      self.dataSource = dataSource;
      [dataSource release];
      }

      - (id<TTTableViewDelegate>) createDelegate
      {
      TTTableViewDragRefreshDelegate *delegate = [[TTTableViewDragRefreshDelegate alloc] initWithController:self];

      return [delegate autorelease];
      }

      // TTTableViewDelegate
      //
      - (void)tableView:(UITableView *)tableView touchesBegan:(NSSet *)touches withEvent:(UIEvent*)event
      {

      }

      - (void)tableView:(UITableView *)tableView touchesEnded:(NSSet *)touches withEvent:(UIEvent*)event
      {

      }

      @end


      現(xiàn)在編譯運(yùn)行,你應(yīng)該可以看到一個(gè) loading 界面,2秒(代碼中有設(shè)定)之后進(jìn)入 tableview 界面,在 tableview 中進(jìn)行下拉操作,可以看到刷新功能以及在里面了!這個(gè)效果和我們使用下拉刷新庫(kù) EGOTableViewPullRefresh 的效果是一樣的。

      posted @ 2011-12-31 17:26  飄飄白云  閱讀(957)  評(píng)論(2)    收藏  舉報(bào)
      本博客遵循 Creative Commons License “署名-非商業(yè)用途-保持一致”創(chuàng)作共用協(xié)議。 與我聯(lián)系
      主站蜘蛛池模板: 国产午精品午夜福利757视频播放| 亚洲色av天天天天天天| 美女扒开尿口让男人桶| 亚洲日韩欧美一区二区三区在线| 亚洲中文字幕无码中字| 久久精品国产福利亚洲av| 日本一区二区不卡精品| 激情综合网激情综合| 亚洲国产成人精品无色码| 狠狠综合久久综合88亚洲| 在线涩涩免费观看国产精品| 天堂V亚洲国产V第一次| 国产成年码AV片在线观看| 蜜桃网址| 成人亚欧欧美激情在线观看| 男女扒开双腿猛进入爽爽免费看| 国产高清在线精品一本大道| 水蜜桃视频在线观看免费18| 欧美老熟妇乱子伦牲交视频 | 久久人妻国产精品| 国产又色又爽又黄的网站免费| 亚洲AV成人片不卡无码| 国精品无码一区二区三区在线| 午夜毛片不卡免费观看视频| 在线 欧美 中文 亚洲 精品| 久久精品国产亚洲欧美| 亚洲综合伊人久久大杳蕉| 中文字幕人妻有码久视频| 亚洲乱理伦片在线观看中字| 成人av午夜在线观看| 亚洲av永久无码精品秋霞电影影院| 99蜜桃在线观看免费视频网站| 日本熟妇人妻一区二区三区| 亚洲色大成成人网站久久| 国产四虎永久免费观看| 亚洲精品国产av成拍色拍个| 亚洲第一精品一二三区| 丰满的少妇一区二区三区| 一区二区乱子伦在线播放| 2021亚洲va在线va天堂va国产| 五月婷之久久综合丝袜美腿 |