欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

iOS購(gòu)物分類模塊的實(shí)現(xiàn)方案

 更新時(shí)間:2016年02月22日 09:00:08   投稿:lijiao  
這篇文章主要為大家詳細(xì)介紹了iOS購(gòu)物分類模塊的實(shí)現(xiàn)方案,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例分享了iOS購(gòu)物分類模塊的實(shí)現(xiàn)方案,供大家參考,具體內(nèi)容如下

啟動(dòng)
在AppDelegate中創(chuàng)建主視圖控制器。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  // Override point for customization after application launch.
  self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  // Override point for customization after application launch.
  self.window.backgroundColor = [UIColor whiteColor];
  [self.window makeKeyAndVisible];
      
  Basetabarcontroller*base=[[Basetabarcontroller alloc]init];
      
  self.window.rootViewController=base;
      
  return YES;
    
}

UI框架設(shè)計(jì)

Basetabbarcontroller基于UITabBarController,作為主視圖控制器。
頭文件如下:

@interface Basetabarcontroller : UITabBarController
    
@end

實(shí)現(xiàn)文件中主要做了2點(diǎn):創(chuàng)建視圖控制器ClassViewController,并將它設(shè)置到新創(chuàng)建的創(chuàng)建導(dǎo)航控制器中。

- (void)viewDidLoad {
  [super viewDidLoad];
  self.tabBar.tintColor = [UIColor redColor];
  // self.tabBar.barTintColor = [UIColor blackColor];
      
   ClassViewController*classList=[[ClassViewController alloc]init];
  //classList.title=@"分類";
     
     
  [self addChildViewController:classList title:@"分類" image:@""];
     
  UIButton *menuBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  menuBtn.frame = CGRectMake(0, 0, 20, 18);
  [menuBtn setBackgroundImage:[UIImage imageNamed:@"1.png"] forState:UIControlStateNormal];
  [menuBtn addTarget:self action:@selector(openOrCloseLeftList) forControlEvents:UIControlEventTouchUpInside];
  self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:menuBtn];
  //self.tabBar.barTintColor = [UIColor redColor];
}
- (void)addChildViewController:(UIViewController *)childController title:(NSString *)title image:(NSString *)image{
      
  UINavigationController *childVC = [[UINavigationController alloc]initWithRootViewController:childController];
  childVC.tabBarItem.title = title;
   childVC.tabBarItem.image = [UIImage imageNamed:image];
  childVC.navigationBar.barTintColor = [UIColor whiteColor];
       
  [self addChildViewController:childVC];
      
    
}

主要的界面視圖控制器定義:

@interface ClassViewController : UIViewController
   
@end

實(shí)現(xiàn)文件中:

- (void)viewDidLoad {
  [super viewDidLoad];
  // Do any additional setup after loading the view.
     
   
  UIBarButtonItem *searchBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(searchBarButtonItemAction)];
  self.navigationItem.rightBarButtonItem = searchBarButtonItem;
    [self setdata];
  [self setimage];
  [self setdeatil];
   
     
  _a=1;
  _b=1;
  _segement=[[UISegmentedControl alloc]initWithItems:@[@"攻略",@"詳情"]];
  _segement.frame=CGRectMake(90, 20, kwidth-180, 30);
  _segement.tintColor=[UIColor blackColor];
  _segement.selectedSegmentIndex=0;
  [_segement addTarget:self action:@selector(changevalue:) forControlEvents:(UIControlEventValueChanged)];
  self.navigationItem.titleView =_segement;
   self.scrollview=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, kwidth, KHeight)];
  _scrollview.directionalLockEnabled=YES;
  _scrollview.contentSize=CGSizeMake(kwidth*2, KHeight);
  _scrollview.delegate=self;
     
     
  [self.view addSubview:self.scrollview];
  UICollectionViewFlowLayout*flow=[[UICollectionViewFlowLayout alloc]init];
    //列距
  flow.minimumInteritemSpacing=20;
     
  //行距
  flow.minimumLineSpacing=40;
    //分區(qū)內(nèi)邊距
  flow.sectionInset=UIEdgeInsetsMake(0, 20, 20, 20);
    CGFloat totalwidth=self.view.frame.size.width;
     
  CGFloat itemwidth=(totalwidth-2*20-3*20)/4.0;
     
  CGFloat itemheight=itemwidth;
     
  flow.itemSize=CGSizeMake(itemwidth, itemheight);
     
  flow.headerReferenceSize=CGSizeMake(0, 40);
     
  //滾動(dòng)方向
  flow.scrollDirection= UICollectionViewScrollDirectionVertical;
  ;
     
  //區(qū)頭大小
  flow.headerReferenceSize=CGSizeMake(0, 100);
     
  _collection=[[UICollectionView alloc]initWithFrame:[UIScreen mainScreen].bounds collectionViewLayout:flow];
  _collection.backgroundColor=[UIColor whiteColor];
  _collection.tag=1;
  _Srr=@[@"1",@"s",@"2",@"r"];
  for (NSString*St in _Srr) {
    [_collection registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:St];}
  //設(shè)置 數(shù)據(jù)源 和代理
  _collection.dataSource=self;
  _collection.delegate=self;
  [_collection registerClass:[ClassCollectionViewCell class] forCellWithReuseIdentifier:@"mycell"];
  // _collection.backgroundColor=[UIColor yellowColor];
  _collection.directionalLockEnabled=YES;
     
  [self.scrollview addSubview:_collection];
  UIView*view=[[UIView alloc]initWithFrame:CGRectMake(kwidth, 0, kwidth, 30)];
  // view.backgroundColor = [UIColor whiteColor];
  UIButton*label=[UIButton buttonWithType:(UIButtonTypeSystem)];
  label.frame=CGRectMake(0, 20, 200, 14) ;
  [label setTitle:@"選禮神器" forState:(UIControlStateNormal)];
  [label addTarget:self action:@selector(xuan) forControlEvents:(UIControlEventTouchUpInside)];
  [view addSubview:label];
  [self.scrollview addSubview:view];

 網(wǎng)絡(luò)數(shù)據(jù)封裝
基于NFNetworking,封裝了3個(gè)接口

@interface LORequestManger : NSObject
   
+ (void)POST:(NSString *)URL params:(NSDictionary * )params success:(void (^)(id response))success
   failure:(void (^)(AFHTTPRequestOperation *operation,NSError *error))Error;
   
   
+ (void)GET:(NSString *)URL
  success:(void (^)(id response))success
  failure:(void (^)(AFHTTPRequestOperation *operation,NSError *error))Error;
   
+ (void)UPLOADIMAGE:(NSString *)URL
       params:(NSDictionary *)params
    uploadImage:(UIImage *)image
      success:(void (^)(id response))success
      failure:(void (^)(AFHTTPRequestOperation *operation,NSError *error))Error;
   
@end

實(shí)現(xiàn)文件:

#import "LORequestManger.h"
#define serverUrl @"http://192.168.1.1:8080/jiekou"
   
@implementation LORequestManger
   
   
   
+ (void)POST:(NSString *)URL params:(NSDictionary * )params success:(void (^)(id response))success
   failure:(void (^)(AFHTTPRequestOperation *operation,NSError *error))Error
{
  // 創(chuàng)建請(qǐng)求管理者
  AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
     
  // 請(qǐng)求超時(shí)時(shí)間
   
  manager.requestSerializer.timeoutInterval = 30;
  NSString *postStr = URL;
  if (![URL hasPrefix:@"http"]) {
       
    postStr = [NSString stringWithFormat:@"%@%@", serverUrl,URL] ;
  }
  NSMutableDictionary *dict = [params mutableCopy];
     
     
  // 發(fā)送post請(qǐng)求
  [manager POST:postStr parameters:dict success:^(AFHTTPRequestOperation *operation, id responseObject) {
       
    // 請(qǐng)求成功
    NSDictionary *responseDict = (NSDictionary *)responseObject;
    success(responseDict);
       
  } failure:^(AFHTTPRequestOperation *operation, NSError *error) {// 請(qǐng)求失敗
    Error( operation,error);
       
  }];
   
   
}
   
+ (void)GET:(NSString *)URL
  success:(void (^)(id response))success
  failure:(void (^)(AFHTTPRequestOperation *operation,NSError *error))Error
{
  // 獲得請(qǐng)求管理者
  AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] init];
  manager.requestSerializer = [AFJSONRequestSerializer serializer];
  [manager.requestSerializer setHTTPShouldHandleCookies:NO];
  manager.requestSerializer.timeoutInterval = 30;
  NSString *getStr = URL;
//  NSLog(@"getStr======%@",getStr);
  if (![URL hasPrefix:@"http"]) {
       
    getStr = [NSString stringWithFormat:@"%@%@", serverUrl,URL] ;
  }
   
     
  // 發(fā)送GET請(qǐng)求
  [manager GET:getStr parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
//    NSLog(@"getStr------------%@",getStr);
    NSDictionary *responseDict = (NSDictionary *)responseObject;
      
      success(responseDict);
   
       
  } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    if (!operation.responseObject) {
      NSLog(@"網(wǎng)絡(luò)錯(cuò)誤");
    }
    Error( operation,error);
  }];
   
     
}
   
+ (void)UPLOADIMAGE:(NSString *)URL
       params:(NSDictionary *)params
    uploadImage:(UIImage *)image
      success:(void (^)(id response))success
      failure:(void (^)(AFHTTPRequestOperation *operation,NSError *error))Error
{
  // 創(chuàng)建請(qǐng)求管理者
  AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
     
  manager.requestSerializer = [AFJSONRequestSerializer serializer];
  manager.responseSerializer = [AFJSONResponseSerializer serializer];
  manager.requestSerializer.timeoutInterval = 30;
  //  [manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
  //
  //  [manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
     
  NSString *postStr = [NSString stringWithFormat:@"%@%@", serverUrl,URL] ;
  NSMutableDictionary *dict = [params mutableCopy];
   
  [manager POST:postStr parameters:dict constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
    NSData *imageData = UIImageJPEGRepresentation(image, 0.1);
    [formData appendPartWithFileData:imageData name:@"img" fileName:@"head.jpg" mimeType:@"image/jpeg"];
       
  } success:^(AFHTTPRequestOperation *operation, id responseObject) {
   
    NSDictionary *responseDict = (NSDictionary *)responseObject;
        success(responseDict);
    
  } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    Error( operation,error);
       
  }];
   
   
   
}

效果:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助。

相關(guān)文章

  • iOS中的UISearchBar搜索框組件基礎(chǔ)使用指南

    iOS中的UISearchBar搜索框組件基礎(chǔ)使用指南

    iOS開(kāi)發(fā)套件中自帶的UISearchBar搜索框我們平時(shí)經(jīng)常可以用到,我們可以在默認(rèn)的基礎(chǔ)上修改文字顏色、背景顏色和背景圖片等,這里我們稍微總結(jié)一下iOS中的UISearchBar搜索框組件基礎(chǔ)使用指南.
    2016-05-05
  • iOS App使用SQLite之句柄的定義及數(shù)據(jù)庫(kù)的基本操作

    iOS App使用SQLite之句柄的定義及數(shù)據(jù)庫(kù)的基本操作

    SQLite中在定義過(guò)句柄之后就可以指向數(shù)據(jù)庫(kù),從而利用iOS應(yīng)用程序進(jìn)行打開(kāi)或關(guān)閉等各種操作,這里我們就來(lái)看一下iOS App使用SQLite之句柄的定義及數(shù)據(jù)庫(kù)的基本操作
    2016-06-06
  • iOS開(kāi)發(fā)使用XML解析網(wǎng)絡(luò)數(shù)據(jù)

    iOS開(kāi)發(fā)使用XML解析網(wǎng)絡(luò)數(shù)據(jù)

    XML解析其實(shí)這個(gè)概念出現(xiàn)了算夠久了,以前javaweb什么到處都在用。這邊我們主要大致介紹下,然后在在ios編程如何使用。
    2016-02-02
  • iOS之基于FreeStreamer的簡(jiǎn)單音樂(lè)播放器示例

    iOS之基于FreeStreamer的簡(jiǎn)單音樂(lè)播放器示例

    這篇文章主要介紹了iOS之基于FreeStreamer的簡(jiǎn)單音樂(lè)播放器示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-11-11
  • iOS擼一個(gè)簡(jiǎn)單路由Router的實(shí)現(xiàn)代碼

    iOS擼一個(gè)簡(jiǎn)單路由Router的實(shí)現(xiàn)代碼

    這篇文章主要介紹了iOS擼一個(gè)簡(jiǎn)單路由Router的實(shí)現(xiàn)代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-09-09
  • 解決iOS UITextField 編輯時(shí)文本偏移問(wèn)題

    解決iOS UITextField 編輯時(shí)文本偏移問(wèn)題

    這篇文章主要介紹了解決iOS UITextField 編輯時(shí)文本偏移問(wèn)題,需要的朋友可以參考下
    2017-05-05
  • iOS實(shí)現(xiàn)獲取系統(tǒng)iTunes音樂(lè)的方法示例

    iOS實(shí)現(xiàn)獲取系統(tǒng)iTunes音樂(lè)的方法示例

    這篇文章主要給大家介紹了關(guān)于iOS如何實(shí)現(xiàn)獲取系統(tǒng)iTunes音樂(lè)的相關(guān)資料,文中通過(guò)示例代碼給大家詳細(xì)介紹了實(shí)現(xiàn)的方法,并給大家介紹了MPMediaPickerController的相關(guān)知識(shí),對(duì)大家的學(xué)習(xí)或者工作具有一定的幫助,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-11-11
  • iOS 生成圖片驗(yàn)證碼(實(shí)用功能)

    iOS 生成圖片驗(yàn)證碼(實(shí)用功能)

    這篇文章主要介紹了iOS 生成圖片驗(yàn)證碼功能,此功能非常實(shí)用,需要的朋友可以參考下
    2017-03-03
  • Flutter使用push pop方法及路由進(jìn)行導(dǎo)航詳解

    Flutter使用push pop方法及路由進(jìn)行導(dǎo)航詳解

    這篇文章主要為大家介紹了Flutter使用push pop方法及路由進(jìn)行導(dǎo)航詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-09-09
  • iOS實(shí)現(xiàn)實(shí)時(shí)檢測(cè)網(wǎng)絡(luò)狀態(tài)的示例代碼

    iOS實(shí)現(xiàn)實(shí)時(shí)檢測(cè)網(wǎng)絡(luò)狀態(tài)的示例代碼

    網(wǎng)絡(luò)連接狀態(tài)檢測(cè)對(duì)于我們的iOS開(kāi)發(fā)來(lái)說(shuō)是一個(gè)非常通用的需求。下面這篇文章主要就給大家介紹了關(guān)于利用iOS實(shí)現(xiàn)實(shí)時(shí)檢測(cè)網(wǎng)絡(luò)狀態(tài)的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起看看吧。
    2017-07-07

最新評(píng)論