天天看點

iPhone SDK開發基礎之iPhone程式架構

書以嚴密的體系性提供了iPhone和iPad軟體開發從入門到專家的系統性知識,并提供來源于真實項目的可重用商業代碼。書中的每個執行個體都是項目經驗的提煉,深入淺出地講解iPhone和iPad軟體開發的核心技術要點,基本涵蓋了iOS軟體開發在真實商業項目中所需要的所有主題,并将執行個體介紹的技術深度和超值的實用性結合在一起,成為本書的特色。 
iPhone SDK開發基礎之iPhone程式架構
iPhone SDK開發基礎之iPhone程式架構

 iOS樣章.rar (6622 K) 下載下傳次數:372 

下面為大家連載此書部分章節供大家讨論。 

                                             iPhone SDK開發基礎之iPhone程式架構 

    總的來說iPhone程式有兩類架構,一類是遊戲架構,另一類是非遊戲架構,這裡介紹的是非遊戲架構,即基于iPhone 使用者界面标準控件的程式架構。 

典型的iPhone程式包含一個Window和幾個UIViewController,每個UIViewController管理多個UIView(可能是UITableView、UIWebView、UIImageView等),如圖3-24所示。這些UIView之間如何進行層次疊放、顯示、隐藏、旋轉、移動等都由UIViewController進行管理,而UIViewController之間的切換,通常情況是通過UINavigationController、UITabBarController或UISplitViewController進行切換。接下來筆者會逐一介紹如何使用這三種Controller來切換你的UIViewController,以及在UIViewController中如何組織和管理你的各種UIView。 

iPhone SDK開發基礎之iPhone程式架構

圖3-24 iPhone程式架構示意圖 

                         iPhone SDK開發基礎之   OpenFlow程式設計 

    當使用者界面需要按頁面顯示圖檔時,使用OpenFlow庫提供的功能,将要顯示的使用者界面圖檔分頁進行顯示會使程式設計工作變得非常快捷。該庫提供了與OS X桌面Finder程式相同的視覺效果,如圖3-46所示就是一個使用OpenFlow庫逐頁進行圖檔顯示的程式,使用者按下螢幕即可進行左右滾動顯示,輕按兩下圖檔即可對目前顯示的圖檔進行選取操作。 

iPhone SDK開發基礎之iPhone程式架構

圖3-46 OpenFlow程式設計執行個體界面 

程式在視圖控制器的viewDidAppear()中使用refreshCoverFlow()函數初始化OpenFlow庫,通過setNumberOfImages()函數設定圖檔數量,代碼如下。 

// RootViewController.m 

- (void)refreshCoverFlow{ 

CGRect bounds = [[UIScreen mainScreen] bounds]; 

AFOpenFlowView *coverFlowView = (AFOpenFlowView*)[self.view viewWithTag:kTagCoverflow]; 

if(coverFlowView != nil) 

[coverFlowView removeFromSuperview]; 

coverFlowView = [[AFOpenFlowView alloc] initWithFrame:CGRectMake(0, -30, bounds.size.width, COVERFLOWHEIGHT)]; 

coverFlowView.dataSource = self; 

coverFlowView.viewDelegate = self; 

coverFlowView.defaultImage = [self defaultImage]; 

coverFlowView.tag = kTagCoverflow; 

[self.view addSubview:coverFlowView]; 

NSInteger count = [self numberOfAnimals]; 

[coverFlowView setNumberOfImages:count]; 

//... 

[coverFlowView release]; 

并在loadView()中初始化圖檔,将圖檔從資源中加載并儲存在一個NSMutableArray類型的變量imageArray中,代碼如下。 

- (BOOL)doAddAnimal:(NSString *)name Image:(NSString *)imageName{ 

UIImage *image = [UIImage imageNamed: imageName]; 

if(image == nil) return FALSE; 

CGSize size = CGSizeMake(179, 208); 

[imageArray addObject:[self resizeImage:image scaledToSize:size]]; 

return TRUE; 

在OpenFlow庫的requestImageForIndex delegate方法中直接通過NSMutableArray的索引作為OpenFlow庫的圖檔索引,并通過該索引設定和擷取具體圖檔,代碼如下。 

// PageViewController.m 

- (void)openFlowView:(AFOpenFlowView *)openFlowView requestImageForIndex: (int)index{ 

UIImage *image = [imageArray objectAtIndex:index]; 

[openFlowView setImage:image forIndex:index]; 

筆者在OpenFlow庫AFOpenFlowView.m檔案的touchesEnded()函數中增加了輕按兩下回調接口,以便在使用者輕按兩下圖檔時通知庫的調用者,代碼如下。 

//AFOpenFlowView.m 

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

if(((UITouch *)[touches anyObject]).tapCount == 2){ 

if ([self.viewDelegate respondsToSelector:@selector(openFlowView: coverViewDoubleClick:)]) 

[self.viewDelegate openFlowView:self coverViewDoubleClick: selectedCoverView.number]; 

[super touchesEnded:touches withEvent:event]; 

庫的調用者RootViewController類通過接口函數coverViewDoubleClick()即可處理使用者輕按兩下事件,代碼如下。 

- (void)openFlowView:(AFOpenFlowView *)openFlowView coverViewDoubleClick:(int)index{ 

NSLog(@"coverViewDoubleClick called!"); 

[self showPaintingViewController]; 

本節相關的完整Xcode工程源代碼檔案請參考本書附帶的CD光牒中的OpenFlow工程。

      分享到: 1

猜你喜歡

  • 【WEIP外翻組專稿】印軟體巨頭Infosys為蘋果軟體開發“大興土木...
  • IOS版股票軟體即将上市 袁璇婧股票軟體開發
  • 承接IPHONE、IPAD電子樓書、展示應用、遊戲等軟體開發
  • 普通的筆記本(不是MAC BOOK)可以開發蘋果手機軟體嗎?
  • 想開發蘋果應用軟體,需要什麼配置的MAC 筆記本?
  • 【原創軟體作者】上海地區收Macbook Pro一台,用于#開發#,内詳
  • 本人開發了火車票訂票軟體,需要的請聯系我!
368元!現在擁有Apple 蘋果 正品 Smart Cover 真皮保護套, 完美你的iPad2/iPad3 回複 引用 舉報 頂端
  broadview  
iPhone SDK開發基礎之iPhone程式架構
級别: 小蘋果
iPhone SDK開發基礎之iPhone程式架構
發帖
38
we券
47
貢獻
經驗
41
人氣
  • 關注Ta
  • 發消息

隻看該作者 1樓 (沙發)   發表于: 2011-06-02 13:35     iPhone SDK開發基礎之UIPageControl程式設計

當使用者界面需要按頁面進行顯示時,使用iOS提供的UIPageControl控件将要顯示的使用者界面内容分頁進行顯示會使程式設計工作變得非常快捷,如圖3-47所示就是一個使用UIPageControl控件逐頁進行圖檔顯示的程式,使用者按下螢幕即可進行左右滾動顯示,在螢幕的正上方使用白色的點顯示目前滾動到的頁面位置。

iPhone SDK開發基礎之iPhone程式架構

圖3-47  UIPageControl程式設計執行個體界面

程式自定義一個SwipeView類,該類通過子類化UIView類并重載其touchesMoved()方法捕獲使用者滾動的方向,類的定義如下。

//  SwipeView.h

#import <UIKit/UIKit.h>

#import <QuartzCore/QuartzCore.h>

@interface SwipeView : UIView {

CGPoint startTouchPosition;

NSString *dirString;

UIViewController *host;

}

- (void) setHost: (UIViewController *) aHost;

@end

//  SwipeView.m

#import "SwipeView.h"

@implementation SwipeView

- (id)initWithFrame:(CGRect)frame {

    if ((self = [super initWithFrame:frame])) {

        // Initialization code

    }

    return self;

}

- (void) setHost: (UIViewController *) aHost

{

host = aHost;

}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 

UITouch *touch = [touches anyObject]; 

startTouchPosition = [touch locationInView:self]; 

dirString = NULL;

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 

UITouch *touch = touches.anyObject; 

CGPoint currentTouchPosition = [touch locationInView:self]; 

#define HORIZ_SWIPE_DRAG_MIN 12 

#define VERT_SWIPE_DRAG_MAX 4 

if (fabsf(startTouchPosition.x - currentTouchPosition.x) >= 

  HORIZ_SWIPE_DRAG_MIN && 

  fabsf(startTouchPosition.y - currentTouchPosition.y) <= 

  VERT_SWIPE_DRAG_MAX)  { 

  // Horizontal Swipe

  if (startTouchPosition.x < currentTouchPosition.x) {

   dirString = kCATransitionFromLeft;

  }

  else 

   dirString = kCATransitionFromRight;

}

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

if (dirString) [host swipeTo:dirString];

}

@end

在捕獲使用者滾動的方向後,SwipeView類通過使用者設定的host成員變量回調其swipeTo()方法,host成員變量在類中定義為UIViewController,在編譯時編譯器會産生警告,這裡不用管它,隻需要SwipeView類的使用者設定host成員變量并實作swipeTo()方法即可。

SwipeView類的使用者為PageViewController類,該類實作程式的主界面,在這個自定義的UIViewController類中實作swipeTo()方法,代碼如下。

//  PageViewController.m

- (void) swipeTo: (NSString *) aDirection{

UIPageControl *pageControl = [[[contentView superview] subviews] lastObject];

if ([aDirection isEqualToString:kCATransitionFromRight])

{

  if (currentPage == 5) return;

  [pageControl setCurrentPage:currentPage + 1];

} else {

  if (currentPage == 0) return;

  [pageControl setCurrentPage:currentPage - 1];

}

[self pageTurn:pageControl];

}

在該回調方法中根據使用者滾動的方向來設定UIPageControl的currentPage屬性,如果是向右方滾動則頁面計數加一,如果使用者滾動的方向是向左,則頁面計數減一。設定UIPageControl的currentPage屬性以後,PageViewController對象再調用其pageTurn()方法交換頁面顯示内容,并将圖檔顯示出來,代碼如下。

- (void) pageTurn: (UIPageControl *) pageControl{

CATransition *transition;

int secondPage = [pageControl currentPage];

if ((secondPage - currentPage) > 0)

  transition = [self getAnimation:@"fromRight"];

else

  transition = [self getAnimation:@"fromLeft"];

UIImageView *newView = (UIImageView *)[[contentView subviews] objectAtIndex:0];

[newView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"ipad_ wallpaper%02d.jpg", secondPage + 1]]];

[contentView exchangeSubviewAtIndex:0 withSubviewAtIndex:1];

[[contentView layer] addAnimation:transition forKey:@"transitionView Animation"];

currentPage = [pageControl currentPage];

}

在主pageTurn()方法實作中,PageViewController類通過UIView的exchangeSubview AtIndex()方法實作頁面内容的切換。

本節相關的完整Xcode工程源代碼檔案請參考本書附帶的CD光牒中的PageControl工程。

本文節選自《iOS軟體開發揭密:iPhone&iPad企業應用和遊戲開發》一書。

《iOS軟體開發揭密:iPhone&iPad企業應用和遊戲開發》一書已由電子工業出版社正式出版,本書由虞斌著。  

    喜歡windows phone滴童鞋也可以去威智WPer (Windows phoner)微軟智能手機愛好者社群逛逛.www.wper.com! 回複 引用 舉報 頂端
  y517039603  
iPhone SDK開發基礎之iPhone程式架構
級别: 紅鑽蘋果
iPhone SDK開發基礎之iPhone程式架構
發帖
7442
we券
8512
貢獻
經驗
7392
人氣
405
  • 關注Ta
  • 發消息
隻看該作者 2樓  發表于: 2011-06-03 12:43     好帖啊·····  
  回複 引用 舉報 頂端
  broadview  
iPhone SDK開發基礎之iPhone程式架構
級别: 小蘋果
iPhone SDK開發基礎之iPhone程式架構
發帖
38
we券
47
貢獻
經驗
41
人氣
  • 關注Ta
  • 發消息

隻看該作者 3樓  發表于: 2011-06-07 09:44     iPhone SDK開發基礎之

使用UINavigationController組織和管理UIView

當你的程式具有階層化的工作流時,就比較适合使用UINavigationController來管理UIViewController,即使用者可以從上一層界面進入下一層界面,在下一層界面處理完以後又可以簡單地傳回到上一層界面,UINavigationController使用堆棧的方式來管理UIViewController,進入下一層界面的代碼如下。

[self.navigationController pushViewController:nextController animated:YES];

傳回上一層界面的代碼如下。

[self.navigationController popViewControllerAnimated:YES];

iPhone SDK開發基礎之iPhone程式架構

如圖3-25所示,螢幕左上方的“Animal List”按鈕是傳回按鈕,注意這個傳回按鈕是UINavigationController自動添加的,不需要編寫任何代碼在界面上添加按鈕或者實作按鈕操作,當程式使用pushViewController()函數将ViewController添加進UINavigation Controller的時候,UINavigationController就自動顯示這個傳回按鈕,使用者單擊這個“Animal List”按鈕就可以回到原先的界面,UINavigationController的這種運作機制産生這樣的效果,使用者可以一層一層地進入更深的界面層次,然後又可以一層一層的按順序傳回,使用這樣的方式來組織使用者界面非常友善。

本節相關的完整Xcode工程源代碼檔案請參考本書附帶的CD光牒中的Zoo執行個體。

本文節選自《iOS軟體開發揭密:iPhone&iPad企業應用和遊戲開發》一書。

《iOS軟體開發揭密:iPhone&iPad企業應用和遊戲開發》一書已由電子工業出版社正式出版,本書由虞斌著。

    回複 引用 舉報 頂端
  broadview  
iPhone SDK開發基礎之iPhone程式架構
級别: 小蘋果
iPhone SDK開發基礎之iPhone程式架構
發帖
38
we券
47
貢獻
經驗
41
人氣
  • 關注Ta
  • 發消息

隻看該作者 4樓  發表于: 2011-06-07 09:47     iPhone SDK開發基礎之

使用UITabBarController組織和管理UIView

當你的程式分為幾個相對比較獨立的部分時,就比較适合使用UITabBarController來組織使用者界面,如圖3-26所示。

iPhone SDK開發基礎之iPhone程式架構

圖3-26  UITabBarController程式架構執行個體界面

在螢幕的下方包含UITabBarController的三個按鈕,使用者單擊不同的按鈕即可以進入不同的界面,每個界面相對來說在整個系統中比較獨立,也就是程式分成了三個相對比較獨立的不同部分,在每個相對獨立的部分你也可以使用UINavigationController等容器類組織你的界面。這樣組織使程式邏輯非常清晰,當然你也可以組織很多個Tab而不隻是三個,以下代碼示範如何建立UITabBarController對象,并為其添加多個Tab。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions {    

    // Override point for customization after application launch.

//Create the navigation Controller

UINavigationController *localNavigationController;

//Create UINavigationController

tabBarController = [[UITabBarController alloc] init];

    tabBarController.delegate = self;

// Create the array that will contain all the View controlelr

NSMutableArray *localControllersArray = [[NSMutableArray alloc] init WithCapacity:3];

// Create the view controller attached to the first item in the TabBar

aViewController *firstViewController;

firstViewController = [aViewController alloc];

localNavigationController = [[UINavigationController alloc] initWithRoot ViewController:firstViewController];

localNavigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;

[localNavigationController.tabBarItem initWithTitle:@"Outlines" 

image:[UIImage imageNamed:@"webcast.png"] tag:1];

firstViewController.navigationItem.title = @"Outlines";

[localControllersArray addObject:localNavigationController];

[localNavigationController release];

[firstViewController release];

// Create the view controller attached to the second item in the TabBar

anotherViewController *secondViewController;

secondViewController = [[anotherViewController alloc] initWithStyle: UITableViewStyleGrouped ];

localNavigationController = [[UINavigationController alloc] initWithRoot ViewController:secondViewController];

[localNavigationController.tabBarItem initWithTitle:@"Q & A" 

   image:[UIImage imageNamed:@"book.png"] tag:2];

[email protected]"Q & A";

[localControllersArray addObject:localNavigationController];

[localNavigationController release];

[secondViewController release];

miscViewController *thirdViewController;

thirdViewController = [[miscViewController alloc] initWithStyle:UITable ViewStyleGrouped ];

localNavigationController = [[UINavigationController alloc] initWithRoot ViewController:thirdViewController];

[localNavigationController.tabBarItem initWithTitle:@"Misc" 

   image:[UIImage imageNamed:@"favorites.png"] tag:3];

[email protected]"Misc";

[localControllersArray addObject:localNavigationController];

[localNavigationController release];

[thirdViewController release];

// load up our tab bar controller with the view controllers

tabBarController.viewControllers = localControllersArray;

// release the array because the tab bar controller now has it

[localControllersArray release];

// add the tabBarController as a subview in the window

[window addSubview:tabBarController.view];

// need this last line to display the window (and tab bar controller)

[window makeKeyAndVisible];

    return YES;

}

捕獲Tab切換事件,擷取目前活動的Tab索引和UIViewController對象,代碼如下。

- (void)tabBarController:(UITabBarController *)barController didSelectView Controller:(UIViewController *)viewController{

NSLog(@"currentController index:%d",viewController, tabBarController.selectedIndex);

UIViewController  *currentController = tabBarController.selectedView Controller;

NSLog(@"currentController: %@",currentController);

}

切換不同的Tab時,隻需要設定UITabBarController的selectedIndex屬性即可,代碼如下。

tabBarController.selectedIndex = 2;

本節相關的完整Xcode工程源代碼檔案請參考本書附帶的CD光牒中的Lessons2執行個體。

本文節選自《iOS軟體開發揭密:iPhone&iPad企業應用和遊戲開發》一書。

《iOS軟體開發揭密:iPhone&iPad企業應用和遊戲開發》一書已由電子工業出版社正式出版,本書由虞斌著。

    回複 引用 舉報 頂端
  broadview  
iPhone SDK開發基礎之iPhone程式架構
級别: 小蘋果
iPhone SDK開發基礎之iPhone程式架構
發帖
38
we券
47
貢獻
經驗
41
人氣
  • 關注Ta
  • 發消息
隻看該作者 5樓  發表于: 2011-06-08 09:14     每天更新~~~~~~~~  
  回複 引用 舉報 頂端
  broadview  
iPhone SDK開發基礎之iPhone程式架構
級别: 小蘋果
iPhone SDK開發基礎之iPhone程式架構
發帖
38
we券
47
貢獻
經驗
41
人氣
  • 關注Ta
  • 發消息

隻看該作者 6樓  發表于: 2011-06-08 09:20     iPhone SDK開發基礎之自定義儀表控件

在iOS開發中,因為程式的需要,有時要自行繪制iPhone SDK沒有提供的界面控件,通常使用QuartzCore.framework即可畫出你所需要的各種圖形,在這裡我們實作一個圓形的“儀表盤”控件,控件的外觀如圖3-48所示,使用者可以通過旋轉儀表控件的指針來設定程式需要的各種系統參數。

iPhone SDK開發基礎之iPhone程式架構

圖3-48 “儀表盤”控件

控件使用兩個UIView來實作儀表控件,并通過CGAffineTransform類來實作儀表指針的旋轉,控件在UIDialView類中實作,UIDialView類的定義如下。

//  UIDialView.h

#import <UIKit/UIKit.h>

@protocol UIDialViewDelegate

@optional

- (void)dialValue:(int)tag Value:(float)value;

@end

@interface UIDialView : UIView {

id<UIDialViewDelegate> delegate;

NSTimer *timer;

UIImageView *iv;

float maxValue,minValue;

CGAffineTransform initialTransform ;

float currentValue;

}

@property(nonatomic,assign)id<UIDialViewDelegate>delegate;

@property CGAffineTransform initialTransform;

@property float currentValue;

@end

在UIDialView類的實作檔案中,通過init()方法讀取圖檔檔案初始化控件背景和指針,代碼如下。

//  UIDialView.m

#import "UIDialView.h"

@interface UIDialView()

-(void)spin:(NSTimer *)timer;

-(float) goodDegrees:(float)degrees;

@end

#define degreesToRadians(degrees) (M_PI * degrees / 180.0)

#define radiansToDegrees(radians) (radians * 180 / M_PI)

static CGPoint delta;

static float deltaAngle;

static float currentAngle;

@implementation UIDialView

@synthesize initialTransform,currentValue;

- (void)dealloc {

[iv release];

    [super dealloc];

}

@synthesize delegate;

- (id)init{

    if ((self = [super init])) {

  self.userInteractionEnabled = YES;

  iv =[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"knob. png"]];

  UIImage *backgroundTile = [UIImage imageNamed: @"clock.png"];

  UIColor *backgroundPattern = [[UIColor alloc] initWithPatternImage: backgroundTile];

  self.contentMode = UIViewContentModeCenter;

  [self setBackgroundColor:backgroundPattern];

  [backgroundPattern release];  

  iv.backgroundColor = [UIColor clearColor]; 

  iv.autoresizesSubviews= YES;  

  self.frame = CGRectMake(0, 0, iv.frame.size.width, iv.frame.size. height);

  [self addSubview:iv];  

  [self bringSubviewToFront:iv];

  [iv release];

  currentValue = 0;

  currentAngle = 0; 

  deltaAngle = 0.0;  

}

    return self;

}

在UIView的touchesBegan()方法中捕獲使用者Touch點的位置,并根據此位置使用atan2()函數計算出控件的初始化角度,代碼如下。

-  (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

UITouch *thisTouch = [touches anyObject];

delta = [thisTouch locationInView:self];

float dx = delta.x  - iv.center.x;

float dy = delta.y  - iv.center.y;

deltaAngle = atan2(dy,dx);

initialTransform = iv.transform;

}

在使用者的旋轉過程中通過設定指針UIView對象的transform屬性實作儀表控件指針伴随使用者手指的旋轉而旋轉,代碼如下。

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{

UITouch *touch = [touches anyObject];

CGPoint pt = [touch locationInView:self];

float dx = pt.x  - iv.center.x;

float dy = pt.y  - iv.center.y;

float ang = atan2(dy,dx);

if (deltaAngle == 0.0) {

  deltaAngle = ang;

  initialTransform = iv.transform;  

}else{

  float angleDif = deltaAngle - ang;

  CGAffineTransform newTrans = CGAffineTransformRotate(initialTransform, -angleDif);

  iv.transform = newTrans;

  float diffValue = [self goodDegrees:radiansToDegrees(angleDif)];  

  currentValue = maxValue - ((maxValue - minValue)/300)*diffValue;

  if(currentValue > 100) currentValue = 100;

if (delegate != nil) {

  [delegate dialValue:self.tag Value:currentValue];

}

}

客戶通過實作UIDialViewDelegate接口協定的dialValue()方法而得到控件的通知消息,代碼如下。

//  DialViewController.h

#import <UIKit/UIKit.h>

#import "UIDialView.h"

@interface DialViewController : UIViewController< UIDialViewDelegate> {

   UIDialView *dialView;

   UILabel *myLabel;

}

- (void)dialValue:(int)tag Value:(float)value{

NSString *str = [NSString stringWithFormat:@"%.1f",v*100];

    [myLabel performSelector:@selector(setText:) withObject:str];

}

本節相關的完整Xcode工程源代碼檔案請參考本書附帶的CD光牒中的DialControl工程。

本文節選自《iOS軟體開發揭密:iPhone&iPad企業應用和遊戲開發》一書。

《iOS軟體開發揭密:iPhone&iPad企業應用和遊戲開發》一書已由電子工業出版社正式出版,本書由虞斌著。

    回複 引用 舉報 頂端
  broadview  
iPhone SDK開發基礎之iPhone程式架構
級别: 小蘋果
iPhone SDK開發基礎之iPhone程式架構
發帖
38
we券
47
貢獻
經驗
41
人氣
  • 關注Ta
  • 發消息

隻看該作者 7樓  發表于: 2011-06-08 09:22     iPhone企業應用執行個體分析之二:

程式處理流程

程式處理流程總體框圖如圖5-4所示。

iPhone SDK開發基礎之iPhone程式架構

圖5-4  程式處理流程圖

(1)使用者啟動程式時,顯示閃屏。

(2)顯示系統主菜單,主要有“我的檔案”、“部門文檔”、“文檔搜尋”和“統計圖查詢”。

(3)使用者選擇“我的檔案”以後顯示需要我處理的文檔清單。

(4)使用者選擇“部門文檔”以後顯示部門清單。

(5)使用者選擇“文檔搜尋”以後顯示搜尋條件設定界面。

(6)使用者選擇部門清單中的部門以後顯示部門進行中的文檔清單。

(7)使用者設定搜尋條件,單擊搜尋以後顯示搜尋結果文檔清單。

(8)在文檔清單界面顯示文檔名稱、文檔辨別碼,并可以前後翻頁。

(9)使用者選擇文檔清單中的文檔時,顯示該文檔的詳情,詳情分為4個頁面顯示,第1頁顯示文檔名稱、作者、日期、狀态等詳細資料;第2頁顯示文檔的附件,使用者單擊附件時可以将附件下載下傳到手機;第3頁顯示文檔處理曆史記錄;第4頁顯示文檔工程流處理界面。

(10)使用者選擇“統計圖查詢”以後顯示統計圖清單。

(11)使用者選擇統計圖清單中的記錄時顯示統計圖。

(12)使用者單擊Info按鈕時顯示程式版本等資訊。

本文節選自《iOS軟體開發揭密:iPhone&iPad企業應用和遊戲開發》一書。

《iOS軟體開發揭密:iPhone&iPad企業應用和遊戲開發》一書已由電子工業出版社正式出版,本書由虞斌著。

    回複 引用 舉報 頂端
  hnzhaihui  
iPhone SDK開發基礎之iPhone程式架構
級别: 紅蘋果
iPhone SDK開發基礎之iPhone程式架構
發帖
393
we券
405
貢獻
經驗
401
人氣
13
  • 關注Ta
  • 發消息
隻看該作者 8樓  發表于: 2011-06-08 12:58     咱能大方點不?發個完整的給大家共享1  
  回複 引用 舉報 頂端
  broadview  
iPhone SDK開發基礎之iPhone程式架構
級别: 小蘋果
iPhone SDK開發基礎之iPhone程式架構
發帖
38
we券
47
貢獻
經驗
41
人氣
  • 關注Ta
  • 發消息

隻看該作者 9樓  發表于: 2011-06-09 09:08     iPhone企業應用執行個體分析之三: 

程式架構分析 

WebDoc Mobile項目是典型的多層流程型系統,是以系統主要使用UINavigation Controller進行使用者界面的導航,這樣當使用者從上一層界面進入下一層界面,在下一層界面的事情處理完以後,又可以友善地傳回到上一層界面,在使用者登入系統以後,系統顯示主菜單,如圖5-6所示。 

主菜單分為4個選項,即“我的檔案”、“部門文檔”、“進階搜尋”和“統計圖”, 主菜單在MainViewController類中實作,該類使用UITableView來對菜單項進行管理, UITableView的資料源使用一個NSMutableArray來提供表格資料,表格繪制時,使用以下指令。 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section{ 

iPhone SDK開發基礎之iPhone程式架構

圖5-6  系統主菜單界面 

return menuList.count; 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath{ 

   NSDictionary *dataDictionary = [menuList    objectAtIndex:indexPath.row]; 

    cell.textLabel.text = [dataDictionary valueForKey:kTitleKey]; 

    return cell; 

傳回表格行數和每行的具體内容,每行表格資料包含下一層ViewController界面的标題和類名稱,當使用者單擊主菜單的菜單項時,程式先使用該類名稱調用NSClassFromString()建立類對象,然後再建立ViewController對象,并将ViewController加入UINavigation Controller中進行界面顯示。 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath{ 

targetViewController = [[NSClassFromString(viewControllerName) alloc] initWithNibName:viewControllerName bundle:nil]; 

[self.navigationController pushViewController:targetViewController animated:YES]; 

在使用者選擇“我的檔案”或者選擇“部門文檔”界面的具體部門後,以及使用“文檔搜尋”功能搜尋文檔後,程式就顯示文檔清單,如圖5-7所示。 

iPhone SDK開發基礎之iPhone程式架構

圖5-7  文檔清單界面 

文檔清單顯示使用DocListViewController類實作,該類包含文檔記錄分頁,前後導航功能,當記錄超過每頁記錄顯示的最大行數時,使用者可以使用前向和後向箭頭進行翻頁,另外在使用者進行搜尋以後,程式也使用這個類來顯示搜尋結果。 

DocListViewController類包含一個UITableView成員變量,程式使用這個表格來顯示文檔清單,表格的資料源使用一個NSMutableArray來存儲和提供資料,這個數組的每個元素都是一個DocumentDetailViewController類執行個體,在文檔清單顯示前使用一個周遊來建立這些DocumentDetailViewController類執行個體。 

for(i = 0; i < nResult; i++){ 

  DocumentDetailViewController *presidentsViewController = 

  [[NSClassFromString(viewControllerName) alloc] 

   initWithNibName:viewControllerName bundle:nil];   

  Document *doc = [objects objectAtIndex:i]; 

  presidentsViewController.title = doc.documentName; 

  [presidentsViewController setDocument:doc]; 

  [controllers addObject:presidentsViewController]; 

  [presidentsViewController release];       

當使用者單擊文檔清單中的某個文檔時,程式就從數組中取出對應的元素,然後顯示DocumentDetailViewController對象。 

- (void)tableView:(UITableView *)tableView 

didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

[tableView deselectRowAtIndexPath:indexPath animated:YES]; 

    NSUInteger row = [indexPath row]; 

if(self.controllers != nil){   

  DocumentDetailViewController *nextController = [self.controllers 

              objectAtIndex:row]; 

  //preload detail, attachment and history. 

  [nextController preLoadData]; 

  //clear cache 

  [self handleWithCache]; 

  //push document detail view... 

  [self.navigationController pushViewController:nextController animated:YES]; 

繼續閱讀