国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

IOS項目-處女作

2019-11-14 19:12:39
字體:
來源:轉載
供稿:網友

我最近一直都有在看關于IOS項目的知識,今天也總算是迎來了我的第一個IOS項目。不巧這個項目并不是從頭開始開發,而是在基礎上維護并添加一些模塊。

噗~不管怎么樣,還是來分析分析一下defaultimage.png"]; } if (image) { CGRect frameImage=CGRectMake(172 *i+70,10, 112, 112); [[UIColor whiteColor]set]; [[UIColor colorWithRed:221/255.0 green:221/255.0 blue:221/255.0 alpha:1]set]; [[UIColor clearColor] set]; [image drawInRect:CGRectInset(frameImage,0,0)]; } [[UIColor colorWithRed:116/255.0 green:109/255.0 blue:88/255.0 alpha:1]set]; NSString *china=[NSString stringWithFormat:@"%@",[dict objectForKey:@"name"]]; [china drawInRect:CGRectMake(172 *i+30,125, width, 30) withFont:[UIFont boldSystemFontOfSize:15]
        lineBreakMode:UILineBreakModeTailTruncation alignment:UITextAlignmentCenter]; i
++; }}- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint pt = [[touches anyObject] locationInView:self]; NSUInteger width = self.bounds.size.width / 4; NSUInteger count = 0; for (NSMutableDictionary * dict in bookArray) { CGRect rect = CGRectMake(width * count++, 0,width, self.bounds.size.height); if (CGRectContainsPoint(rect, pt)) { //NSLog(@"dict %@",dict); perDict=dict; if(delegate && [delegate respondsToSelector:@selector(getPerSonProduct:)]){ [delegate getPerSonProduct:self]; return; } } }}- (void)dealloc { [super dealloc];}@end

 

看到這里我已經完全暈掉了,完全不知這個是用來干什么的?算了還是回到原來的路去吧,之前我們是看到了FFHomePageViewController.h。FFHomePageViewController.h是實現了FFHomeViewControllerDelegate接口,所以我們才會看到上述兩個文件的。那現在我們來看下FFHomePageViewController.m的構造函數吧~

FFHomePageViewController.m ---> init構造函數(從這個構造函數可以發現bookData是用來存儲bookMenu.plist加載到內存中的鍵值對的)

-(id)init {    if(self= [super init]){        NSString *contentPath = [NSString stringByAppendDocumentDirectory:@"bookMenu.plist"];        bookData=[[NSMutableArray alloc] initWithContentsOfFile:contentPath];    }    return self;}

 

FFHomePageViewController.m ---> loadView方法

//每次訪問UIViewController的view(比如controller.view、self.view)而且view為nil,loadView方法就會被調用。- (void)loadView {    [super loadView];    //指定view的背景顏色    self.view.backgroundColor=[UIColor colorWithRed:235/255.0 green:232/255.0 blue:222/255.0 alpha:1];    //Logo圖片    UIImageView *upImage=[[UIImageView alloc] initWithFrame:CGRectMake(0,0, 768, 88)];    upImage.tag=51;    [upImage setImage:[UIImage imageNamed:@"Ipadup"]];    [self.view  addSubview:upImage];    [upImage release];    //TableView放一些菜單圖標    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 88, 768, 830-5) style:UITableViewStylePlain];    [tableView setDelegate:self];    [tableView setDataSource:self];    [tableView setTag:111110];    tableView.separatorStyle=UITableViewCellSeparatorStyleNone;    tableView.separatorColor=[UIColor clearColor];    [tableView setBackgroundColor:[UIColor clearColor]];    [self.view addSubview:tableView];    [tableView release];    }

 

話說FFHomePageViewController.h是實現UITableViewDataSource接口和UITableViewDelegate接口的,又通過[tableView setDelegate:self],[tableView setDataSource:self]語句,表示只要在FFHomePageViewController.m當前類重寫那些方法就可以了。

UITableViewDataSource,主要為UITableView提 供顯示用的數據(UITableViewCell),指定UITableViewCell支持的編輯操作類型(insert,delete和 reordering),并根據用戶的操作進行相應的數據更新操作,如果數據沒有更具操作進行正確的更新,可能會導致顯示異常,甚至crush。

UITableViewDelegate,主要提供一些可選的方法,用來控制tableView的選擇、指定section的頭和尾的顯示以及協助完成cell的刪除和排序等功能。

接下來看下渲染每一個cell的方法

FFHomePageViewController.m ---> - (UITableViewCell *)tableView:(UITableView *)tableView1 cellForRowAtIndexPath:(NSIndexPath *)indexPath

//初始化每一行會調用該方法- (UITableViewCell *)tableView:(UITableView *)tableView1 cellForRowAtIndexPath:(NSIndexPath *)indexPath {        UITableViewCell *cell = nil;        static NSString *kCellTextField1 = @"Cell";    cell = [tableView1 dequeueReusableCellWithIdentifier:kCellTextField1];    if (cell==nil) {        if (indexPath.section==0) {            //初始化Image            UIImage * bgImage = nil;            bgImage = [[UIImage imageNamed:@"shuguiback.png"] stretchableImageWithLeftCapWidth:0 topCapHeight:34];            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellTextField1] autorelease];            cell.selectionStyle = UITableViewCellSelectionStyleNone;            cell.accessoryType=UITableViewCellAccessoryNone;            //自定義的FFHomeView類構造函數返回自己本身            FFHomeView *drawFriends=[[FFHomeView alloc]initWithFrame:CGRectMake(0, 0,320, 160)];            [drawFriends setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];            [drawFriends setTag:1];            //FFHomeView的delegate就是FFHomeViewControllerDelegate            //而當前類就是實現FFHomeViewControllerDelegate接口的。就是把FFHomeView中要做的事,交給當前類            [drawFriends setDelegate:self];            [drawFriends setUserInteractionEnabled:YES];            [cell.contentView addSubview:drawFriends];            [drawFriends release];            cell.backgroundView=[[UIImageView alloc]initWithImage:bgImage];        }    }    //這里還沒怎么看的明白    if (indexPath.section==0) {        if (bookData) {            NSUInteger count  = [bookData count];            NSUInteger length = indexPath.row * ROWCALUE_NUMBER + ROWCALUE_NUMBER > count?count - indexPath.row * ROWCALUE_NUMBER:ROWCALUE_NUMBER;            NSArray * array = [bookData subarrayWithRange:NSMakeRange(indexPath.row * ROWCALUE_NUMBER , length)];            if (array) {                FFHomeView * view1 = (FFHomeView * )[cell.contentView viewWithTag:1];                view1.bookArray=array;                //setNeedsDisplay會調用自動調用drawRect方法                [view1 setNeedsDisplay];            }        }    }    return cell;}

 

看了這個方法后差不多也明白了之前的FFHomeView.m文件做的是什么事情了,按照java的理解方式是這樣的。就相當于在FFHomeView類中寫了一個事件接口FFHomeViewControllerDelegate,在該類的touchesEnded事件函數中回調FFHomeViewControllerDelegate接口里的getPerSonProduct方法。而getPerSonProduct方法真正的實現而在FFHomePageViewController類當中。

然后調用順序就是:

當我們觸發菜單欄的圖標--->調用FFHomeView里的touchesEnded事件--->再調用到FFHomePageViewController里的getPerSonProduct事件

FFHomePageViewController.m ---> getPerSonProduct方法

-(void)getPerSonProduct:(FFHomeView *)controllerRenqi{    //在FFHomeView內部調用該函數的時候把自己本身傳入,而自己本身包含perDict鍵值對    //<dict><key>url</key><string>/index.php/cms/item-hjindex</string></dict>    NSString *stringURL=[controllerRenqi.perDict objectForKey:@"url"];    if ([stringURL isEqualToString:@"exit"]) {        //若退出,顯示登陸界面        FFLrcController *publish = [[FFLrcController alloc]init];        UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:publish];        [self presentModalViewController:nav animated:NO];        //每次使用完controller都釋放掉        [publish release];        return;    }    NSString *createurl=[controllerRenqi.perDict objectForKey:@"createurl"];    //WebViewController    FFFFWebViewController * web=[[FFFFWebViewController  alloc] init:stringURL createURL:createurl];    NSString *name=[controllerRenqi.perDict objectForKey:@"name"];    web.TT=name;    web.hidesBottomBarWhenPushed=YES;    [self.navigationController pushViewController:web animated:YES];    [web release];    }

 

看完上面這些代碼后,發現接下來的視圖傳入的是WebViewController,參數是url。我想這個一定是傳說中的app中加個webview。大部分操作可能會由webview來實現。
另外我想你會跟我一樣有這樣的一些問題,createurl是什么?干什么用?不急不急,接下來來看看FFFFWebViewController 是怎么實現的。

#import <UIKit/UIKit.h>#import "FFFFSwitchViewController.h"//發現這個類是繼承UIViewController,并實現了UIWebViewDelegate接口@interface FFFFWebViewController : UIViewController <UIWebViewDelegate>{    //瀏覽器    UIWebView * webView;    //UIActivityIndicatorView實例提供輕型視圖,這些視圖顯示一個標準的旋轉進度輪。    UIActivityIndicatorView *activityIndicator;    NSString *stringUrl;    NSString *createUrl;    NSString *TT;}@property(nonatomic,retain)NSString *TT; @property(nonatomic,retain)NSString *stringUrl;@property(nonatomic,retain)NSString *createUrl;-(id)init:(NSString *)string createURL:(NSString*)curl;//-(void)loadWebView:(NSString*)string;@end

 

FFFFWebViewControlle.h主要就是實現了 UIWebViewDelegate委托接口,UIWebViewDelegate主要有下面幾個方法。
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType; //加載前

- (void)webViewDidStartLoad:(UIWebView *)webView;//開始發送請求(加載數據)時調用這個方法
- (void)webViewDidFinishLoad:(UIWebView *)webView;//請求完畢(加載數據完畢)時調?這個方法
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error;//請求錯誤時調用這個方法
 
FFFFWebViewController.m ---> init構造函數方法
//第一個參數為:要顯示的地址-(id)init:(NSString *)string createURL:(NSString*)curl{    if(self=[super init]){        self.stringUrl=[[NSString stringWithFormat:@"%@%@", @"http://xxxxx/hjjd", string] 
          stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; self.createUrl
= curl; } return self;}

 

FFFFWebViewController.m ---> loadView方法

- (void)loadView {    [super loadView];    self.view.backgroundColor=[UIColor colorWithRed:235/255.0 green:232/255.0 blue:222/255.0 alpha:1];    //存放logo    UIImageView *uv=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 768, 60)];    uv.tag=1;    [uv setImage:[UIImage imageNamed:@"Ipadnavigation"]];    [self.view addSubview:uv];    [uv release];    //返回按鈕    UIButton *check = [UIButton buttonWithType:UIButtonTypeCustom];    check.tag=2;    check.frame =CGRectMake(10, 22, 48, 30);    [check.titleLabel setFont:[UIFont boldSystemFontOfSize:14]];      [check setTitle:@"返回" forState:UIControlStateNormal];    //點擊后出發goBack事件    [check addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchDown];    [check setBackgroundImage:[UIImage imageNamed:@"IpadnClose"] forState:UIControlStateNormal];    [self.view addSubview:check];    //新建按鈕    if(![self.createUrl isEqualToString:@"null"]){        UIButton *upButton = [UIButton buttonWithType:UIButtonTypeCustom];        upButton.tag=3;        upButton.frame =CGRectMake(768-58, 22, 48, 30);        [upButton setTitle:@"新建" forState:UIControlStateNormal];        [upButton.titleLabel setFont:[UIFont boldSystemFontOfSize:14]];        //點擊后觸發resum事件        [upButton addTarget:self action:@selector(resum) forControlEvents:UIControlEventTouchDown];        [upButton setBackgroundImage:[UIImage imageNamed:@"IpadnClose"] forState:UIControlStateNormal];        [self.view addSubview:upButton];    }        //標題    UILabel *titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(0,23,768,30)];    titleLabel.tag=4;    [titleLabel setFont:[UIFont boldSystemFontOfSize:20]];    [titleLabel setTextAlignment:UITextAlignmentCenter];    titleLabel.lineBreakMode=UILineBreakModeWordWrap;    titleLabel.numberOfLines=0;    titleLabel.text =TT;    [titleLabel setTextColor:[UIColor whiteColor]];    [titleLabel setBackgroundColor:[UIColor clearColor]];    [self.view addSubview:titleLabel];    [titleLabel release];          webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 60, 768, 1024-20-88-88+60)];    webView.scalesPageToFit = YES;    //設置delegate為本身,因為該類實現UIWebViewDelegate接口    webView.delegate = self;    webView.backgroundColor = [UIColor clearColor];    [self.view addSubview:webView];    
activityIndicator
= [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(0, 15, 50, 50)]; [activityIndicator setCenter:CGPointMake(768/2,1024/2)]; [activityIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray]; [self.view addSubview:activityIndicator]; //加載鏈接地址 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.stringUrl]]];}

 

FFFFWebViewController.m ---> resum事件

-(void)resum{    FFcreateViewContonroller *matchset=[[FFcreateViewContonroller alloc]init:self.createUrl];    matchset.TT=[NSString stringWithFormat:@"新建%@",TT];    [self presentModalViewController:matchset animated:YES];    [matchset release];}


FFFFWebViewController.m ---> goBack事件

- (void)goBack {    //假如瀏覽器可以goBack就先goBack    if([webView canGoBack]){        [webView goBack];    }else{        //否則彈出controller        [self.navigationController popViewControllerAnimated:YES];    }}

 

從上面的代碼就可以看出createurl是用來做什么的了,假如我們點擊右上角的新建按鈕,createurl可以讓webview轉跳到自己定義的頁面當中。另外假如自己需要controller之間的轉跳,則只要在新建點擊后判斷createurl的內容,就可以任意轉跳到自己的地方了。到這里差不多可以看懂原作者的app設計思路是怎么樣的了。這里點擊新建后會進入
FFcreateViewContonroller。FFcreateViewContonroller其實與FFFFWebViewController非常的相似,也就是嵌入一個webview。

源代碼已經分析的差不多了,稍微的總結那么一下。
這個項目的順序是這樣的:AppDelegate_iPad--->FFADSViewController--->FFLrcController
--->FFFFSwitchViewControoler(FFHomePageViewController,FFCamera,FFVideo,FFshezhi)
由FFHomePageViewController出發:FFHomePageViewController--->FFFFWebViewController--->FFcreateViewContonroller

假如要添加某個新功能的話,就可以新建一個controller,然后在resum方法中添加一個判斷引導到新建controller就可以了。若需要在新建的controller下面再進入新的controller其實也無妨,popViewController后FFFFWebViewController始終還會在那邊的。若新建按鈕需要對webview中的內容進行重定向,那就更簡單了,直接在resum方法中調用webview的loadRequest方法,填入需要轉跳的url就可以了。
到這里文章已經寫完了,寫的不好希望大家指出!謝謝大家觀看~
 

上一篇:IOS應用程序啟動加載過程(從點擊圖標到界面顯示)

下一篇:Objetive-C學習_Block學習筆記

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
學習交流
熱門圖片

新聞熱點

疑難解答

圖片精選

網友關注

主站蜘蛛池模板: 建阳市| 吴川市| 清水河县| 唐山市| 共和县| 杨浦区| 鹿邑县| 安吉县| 营山县| 寻甸| 合水县| 凤城市| 西青区| 大邑县| 茶陵县| 萨嘎县| 施甸县| 盈江县| 三都| 富源县| 南江县| 丰镇市| 抚松县| 绵阳市| 临沧市| 新民市| 花垣县| 黄浦区| 栾川县| 清镇市| 礼泉县| 开远市| 闽清县| 临江市| 类乌齐县| 通河县| 应城市| 宜宾县| 乐昌市| 衡山县| 临澧县|