日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

UINavigationController使用的一些技巧

發布時間:2025/3/21 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 UINavigationController使用的一些技巧 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1,創建并使用一個UINavigationController

[html]?view plaincopy
  • UINavigationController?*aNav?=?[[UINavigationController?alloc]?init];??
  • 然后添加一個視圖進去,否則導航欄也沒有意義的

    [html]?view plaincopy
  • UIViewController?*aView?=?[[UIView?alloc]?initWithNibName:?(*xib文件名*)];[aNav?pushViewController:aView?animated:NO];??
  • //導航欄的第一個視圖不要動畫化
    2,設置導航欄的左右按鈕:
    我說過,設置導航欄的按鈕并不是去設置導航欄本身,而是當時被導航的視圖控制器,比如我們對aView作設置。

    設置其標題:

    ?

    [html]?view plaincopy
  • aView.title?=?@"標題";?//配置一個按鈕??
  • IBarButtonItem?*callModalViewButton?=?[[UIBarButtonItem?alloc]??initWithTitle:@"經文"???????
  • ???????????????????????????????????????????????????????????????????????style:UIBarButtonItemStyleBordered????
  • ??????????????????????????????????????????????????????????????????????target:self???????
  • ??????????????????????????????????????????????????????????????????????action:@selector(callModalList)];??
  • ?self.navigationItem.leftBarButtonItem?=?callModalViewButton;??
  • [callModalViewButton?release];?//由于本地視圖會retain它,所以我們可以release了??
  • 可以看到,還是很簡單的嘛。

    3,其他常用方法和屬性:

    ?

    [html]?view plaincopy
  • self.navigationItem.leftBarButtonItem?//左邊欄項目本地視圖??
  • self.navigationItem.rightBarButtonItem?//右邊欄項目本地視圖.??
  • self.navigationItem.backBarButtonItem?//后退欄項目本地視圖.??
  • self.navigationItem.hidesBackButton?//隱藏后退按鈕(YES?or?NO)??
  • 在視圖的viewWillAppear:方法中添加:?

    [html]?view plaincopy
  • [self.tableView?reloadData];??
  • ?不起作用,viewWillAppear:這個方法根本沒有調用

    后來發現原來用了UINavigationController后,viewWillAppear方法是沒有效果的,要用UINavigationControllerDelegate的

    ?

    [html]?view plaincopy
  • –?navigationController:willShowViewController:animated:??
  • 方法才可以達到這個目的。

    ?

    所以要做到這個,你必須做以下幾步:
    1. 設置代理類?nav.delegate = self;
    2. 代理類實現UINavigationControllerDelegate Protocol
    3. 在代理類中添加– navigationController:willShowViewController:animated:方法
    如:

    [html]?view plaincopy
  • -?(void)navigationController:(UINavigationController?*)navigationController?willShowViewController:(UIViewController?*)viewController?animated:(BOOL)animated?{??
  • [self.myTableView?reloadData];??
  • }??
  • [html]?view plaincopy
  • pushViewController:viewController?animated:BOOL??
  • (加載視圖控制器)– 添加指定的視圖控制器并予以顯示,后接:是否動畫顯示

    [html]?view plaincopy
  • popViewControllerAnimated:BOOL??
  • (彈出當前試圖控制器)– 彈出并向左顯示前一個視圖

    [html]?view plaincopy
  • popToViewController:viewController?animated:BOOL??
  • (彈出到制定視圖控制器)– 回到指定視圖控制器, 也就是不只彈出一個

    [html]?view plaincopy
  • popToRootViewControllerAnimated:BOOL??
  • (彈出到根視圖控制器)– 比如說你有一個“Home”鍵,也許就會實施這個方法了。

    [html]?view plaincopy
  • setNavigationBarHidden:BOOL?animated:BOOL??
  • (設置導航欄是否顯示)– 如果你想隱藏導航欄,這就是地方了。參照Picasa的WebApp樣式?
    ?現pushViewController:animated:的不同頁面轉換特效
    1. 首先要明確的是,不使用pushViewController的默認動畫,所以在調用這個函數時,要將animated設置為NO.
    2. 使用普通的來CATransition實現轉換效果,代碼如下:

    [html]?view plaincopy
  • CATransition?*animation?=?[CATransition?animation];??
  • [animation?setDuration:0.3];??
  • [animation?setType:?kCATransitionMoveIn];??
  • [animation?setSubtype:?kCATransitionFromTop];??
  • [animation?setTimingFunction:[CAMediaTimingFunction?functionWithName:kCAMediaTimingFunctionDefault]];??
  • [self.navigationController?pushViewController:m_poseAddIssueViewController?animated:NO];??
  • [self.navigationController.view.layer?addAnimation:animation?forKey:nil]; ?
  • 轉載于:https://www.cnblogs.com/sell/archive/2013/01/18/2865861.html

    總結

    以上是生活随笔為你收集整理的UINavigationController使用的一些技巧的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。