iOS_21團購_UICollectionView的基本使用,ios中uiwebview

來源:互聯網
上載者:User

iOS_21團購_UICollectionView的基本使用,ios中uiwebview

最終:



程式碼片段:

DealListController繼承自UICollectionViewController

self.view已經包含了一個UICollectionView

並且資料來源和代理已經是當前控制器self

////  DealListController.m//  帥哥_團購////  Created by beyond on 14-8-14.//  Copyright (c) 2014年 com.beyond. All rights reserved.//  點擊dock上面的【團購】按鈕對應的控制器,上面是導覽列,導覽列右邊是searchBar,導覽列左邊是一個大按鈕(TopMenu)(內部由三個小按鈕組成<TopMenuItem>)#import "DealListController.h"// 導覽列左邊是一個大按鈕(頂部菜單)#import "TopMenu.h"#define kItemW 250#define kItemH 250@implementation DealListController// 覆蓋控制器的init方法- (id)init{    // 建立一個流布局    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];    // 設定流布局裡面的每一個格子寬和高,即每一個網格的尺寸    layout.itemSize = CGSizeMake(kItemW, kItemH);        // 調用父類UICollectionViewController的initWithCollectionViewLayout方法,(self這兒找不到,會到父類裡去找方法)    return [self initWithCollectionViewLayout:layout];}- (void)viewDidLoad{    [super viewDidLoad];        // 1.頂部導覽列的基本設定    [self setNavigationBar];        // 2.collectionView的基本設定    [self setCollectionView];}// 2.頂部導覽列的基本設定- (void)setNavigationBar{        // 1.右邊的搜尋方塊    UISearchBar *s = [[UISearchBar alloc] init];    s.frame = CGRectMake(0, 0, 210, 35);    s.placeholder = @"請輸入商品名、地址等";    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:s];        // 2.左邊的功能表列    TopMenu *top = [[TopMenu alloc] init];    // 重要,TopMenu裡面的item點擊後,建立的PopMenu將要添加到哪兒去???就是本控制器的view    top.controllerView = self.view;    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:top];        }// 3.collectionView的基本設定- (void)setCollectionView{    // 1.設定collectionView的背景色,(不像tableViewController,本控制器的view是UIView,在UIView裡面再添加的collectionView)    self.collectionView.backgroundColor = kGlobalBg;        // 2.重要~~~註冊cell要用到的xib    [self.collectionView registerNib:[UINib nibWithNibName:@"DealCell" bundle:nil] forCellWithReuseIdentifier:@"DealCell"];        // 3.設定collectionView永遠支援垂直滾動,為下拉重新整理準備(彈簧)    self.collectionView.alwaysBounceVertical = YES;    }// 4.重要~~~因為在控制器建立時,寬預設是768,高預設是1024,不管橫豎屏// 只有在viewWillAppear和viewDidAppear方法中,可以取得view最準確的(即實際的)寬和高(width和height)- (void)viewWillAppear:(BOOL)animated{    // 預設計算layout    [self didRotateFromInterfaceOrientation:0];}#pragma mark - 父類方法// 攔截,螢幕即將旋轉的時候調用(控制器監控旋轉螢幕)- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{    log(@"螢幕即將旋轉");}// 攔截,旋轉螢幕完畢的時候調用- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{    // 1.取出建立CollectionViewController時傳入的的UICollectionViewFlowLayout    UICollectionViewFlowLayout *layout = (UICollectionViewFlowLayout *)self.collectionView.collectionViewLayout;            // 2.計算間距    CGFloat v = 0;    CGFloat h = 0;    CGFloat height = self.view.frame.size.height -44;    CGFloat width = self.view.frame.size.width;    if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)        ) {        // 橫屏的間距        v = (height - 2 * kItemH) / 3;        h = (width - 3 * kItemW) / 4;            } else {        // 豎屏的間距        v = (height - 3 * kItemH) / 4;        h = (width - 2 * kItemW) / 3;    }    // 3.動畫調整格子之間的距離    [UIView animateWithDuration:4.0 animations:^{        // 上 左 下 右 四個方向的margin        layout.sectionInset = UIEdgeInsetsMake(v, h, v, h);        // 每一行之間的間距        layout.minimumLineSpacing = v;    }];}#pragma mark - collectionView代理方法// 共有多少個Item(就是格子Cube)- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{    return 6;}// 產生每一個獨一無二的格子- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{    static NSString *cellID = @"DealCell";    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];        // 設定獨一無二的資料    return cell;}


CollectionView中的格子一般外觀一致,可以用xib

DealCell.xib










silverlight PagedCollectionView在哪個命名空間

這個貌似是toolkit 裡面的! 分頁導航吧! 去官網下載一個toolkit 就知道了! 哪裡還有dome的執行個體協助你使用它 ~~~!
 
Flex undefined 異常 at mxcollections::ListCollectionView/get length()[E:\dev\4y\frameworks\proje

數組是null,但是你使用了 數組.lenth()方法
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.