iOS iPad開發(fā)~demo

//聯(lián)系人:石虎QQ: 1224614774昵稱:嗡嘛呢叭咪哄

/**

注意點(diǎn): 1.看 GIF 效果圖.

2.看連線視圖的效果圖.

3.看實(shí)現(xiàn)代碼(直接復(fù)制實(shí)現(xiàn)效果).

*/

一咆瘟、GIF 效果圖:

二佳簸、連線視圖的效果圖:

圖1:

圖2:

三、實(shí)現(xiàn)代碼:

=========================

===================================================

====================

控制器1:AppDelegate.h

//? Created by石虎on 2017/8/7.

//? Copyright ? 2017年shihu. All rights reserved.

//

#import

@classSHDetailViewController,SHRootTableViewController;

@interfaceAppDelegate :UIResponder

@property(strong,nonatomic)UIWindow*window;

//詳情界面

@property(nonatomic,strong)SHDetailViewController*detailVC;

//左側(cè)邊欄的表格界面

@property(nonatomic,strong)SHRootTableViewController*rootVC;

//邊欄控制器(自動(dòng)添加了手勢自動(dòng)彈回功能)

@property(nonatomic,strong)UISplitViewController*spiltVC;

@end

==========

======

====

控制器1:AppDelegate.m

//

//? Created by石虎on 2017/8/7.

//? Copyright ? 2017年shihu. All rights reserved.

//

#import"AppDelegate.h"

#import"SHRootTableViewController.h"

#import"SHDetailViewController.h"

@interfaceAppDelegate()

@end

@implementationAppDelegate

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

self.rootVC= [[SHRootTableViewControlleralloc]initWithStyle:UITableViewStylePlain];

self.rootVC.navigationItem.title=@"導(dǎo)航視圖";

UINavigationController*rootNav = [[UINavigationControlleralloc]initWithRootViewController:self.rootVC];

self.detailVC= [[SHDetailViewControlleralloc]init];

self.detailVC.navigationItem.title=@"詳情視圖";

UINavigationController*detailNav = [[UINavigationControlleralloc]initWithRootViewController:self.detailVC];

//使用iPad專用控件實(shí)現(xiàn)分欄效果

self.spiltVC= [[UISplitViewControlleralloc]init];

//設(shè)置分欄試圖先后順序決定了左右關(guān)系

self.spiltVC.viewControllers =@[rootNav,detailNav];

self.spiltVC.delegate =self.detailVC;

//設(shè)置為窗口的跟視圖控制器

self.window.rootViewController =self.spiltVC;

returnYES;

}

=========================

===================================================

====================

控制器2:

//? iPad開發(fā)dome

//

//? Created by石虎on 2017/8/7.

//? Copyright ? 2017年shihu. All rights reserved.

//

#import"SHRootTableViewController.h"http://左側(cè)邊欄的表格界面

#import"SHDetailViewController.h"

#import"AppDelegate.h"

@interfaceSHRootTableViewController()

//圖片名稱數(shù)組

@property(nonatomic,strong)NSArray*imgTitleArr;

//圖片數(shù)組

@property(nonatomic,strong)NSArray*imgArr;

@end

@implementationSHRootTableViewController

- (void)viewDidLoad {

[superviewDidLoad];

self.imgTitleArr=@[@"大眾",@"法拉利",@"寶馬",@"奔馳",@"JEEP",@"邁巴赫",@"蘭博基尼"];

//通過循環(huán)將圖片數(shù)組初始化

NSMutableArray*arr = [[NSMutableArrayalloc]init];

for(inti =1; i <=7; i++) {

NSString*imgName = [NSStringstringWithFormat:@"car%d.jpg",i];

UIImage*img = [UIImageimageNamed:imgName];

[arr addObject:img];

}

//

self.imgArr = [arr copy];

}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

return1;

}

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

returnself.imgArr.count;

}

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

staticNSString *identifier =@"cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

//緩存池

if(cell ==nil) {

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];

}

cell.textLabel.text =self.imgTitleArr[indexPath.row];

returncell;

}

//跳轉(zhuǎn)

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

{

//得到在Appdele中實(shí)例化的DetailViewController對(duì)象的內(nèi)存

AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;

SHDetailViewController *detaiVC = appDelegate.detailVC;

detaiVC.imgView.image =self.imgArr[indexPath.row];

}

@end

=========================

===================================================

====================

控制器3:SHDetailViewController.h

//? Created by石虎on 2017/8/7.

//? Copyright ? 2017年shihu. All rights reserved.

//

#import

@interfaceSHDetailViewController :UIViewController

//顯示圖片

@property(strong,nonatomic)IBOutletUIImageView*imgView;

@end

控制器3:SHDetailViewController.m

//

//? Created by石虎on 2017/8/7.

//? Copyright ? 2017年shihu. All rights reserved.

//

#import"SHDetailViewController.h"

#import"AppDelegate.h"

#import"SHRootTableViewController.h"http://左側(cè)邊欄的表格界面

@interfaceSHDetailViewController()

@end

@implementationSHDetailViewController

- (void)viewDidLoad {

[superviewDidLoad];

//導(dǎo)航欄

self.navigationItem.rightBarButtonItem= [[UIBarButtonItemalloc]initWithTitle:@"主菜單"style:UIBarButtonItemStylePlaintarget:selfaction:@selector(showPopOverController:)];

AppDelegate*app = (AppDelegate*)[UIApplicationsharedApplication].delegate;

app.spiltVC.displayModeButtonItem.title=@"顯示導(dǎo)航欄";

self.navigationItem.leftBarButtonItem =? app.spiltVC.displayModeButtonItem;

}

//回調(diào)方法

-(void)showPopOverController:(UIBarButtonItem *)sender

{

//左側(cè)邊欄的表格界面

SHRootTableViewController *rootVC = [[SHRootTableViewController alloc] initWithStyle:UITableViewStylePlain];

//彈出視圖

UIPopoverController *popCtl = [[UIPopoverController alloc] initWithContentViewController:rootVC];

//彈出視圖大小

popCtl.popoverContentSize = CGSizeMake(200,300);

popCtl.backgroundColor = [UIColor yellowColor];

popCtl.delegate =self;

//彈出該視圖

[popCtl presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

}

#pragma mark - UIPopoverControllerDelegate

- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController

{

NSLog(@"將要隱藏彈出視圖");

returnYES;

}

- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController

{

NSLog(@"彈出視圖已經(jīng)隱藏");

}

#pragma mark - UISplitViewControllerDelegate

//左側(cè)導(dǎo)航欄將要出現(xiàn)或隱藏時(shí)回調(diào)此方法

-(void)splitViewController:(UISplitViewController *)svc willChangeToDisplayMode:(UISplitViewControllerDisplayMode)displayMode

{

//左側(cè)導(dǎo)航欄隱藏

if(displayMode == UISplitViewControllerDisplayModePrimaryHidden)

{

NSLog(@"左側(cè)導(dǎo)航將要隱藏");

AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;

app.spiltVC.displayModeButtonItem.title =@"顯示導(dǎo)航欄";

//

svc.displayModeButtonItem.title =@"顯示導(dǎo)航欄";

self.navigationItem.leftBarButtonItem = app.spiltVC.displayModeButtonItem;

}

elseif(displayMode == UISplitViewControllerDisplayModePrimaryOverlay)

{

NSLog(@"左側(cè)導(dǎo)航覆蓋到詳情視圖上");

}

elseif(displayMode == UISplitViewControllerDisplayModeAllVisible)

{NSLog(@"左側(cè)導(dǎo)航全部顯示");

self.navigationItem.leftBarButtonItem =nil;

}else{NSLog(@"自動(dòng)顯示");}}

@end

謝謝!!!

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市吼蚁,隨后出現(xiàn)的幾起案子讶凉,更是在濱河造成了極大的恐慌,老刑警劉巖瘫辩,帶你破解...
    沈念sama閱讀 221,331評(píng)論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件伏嗜,死亡現(xiàn)場離奇詭異坛悉,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)承绸,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,372評(píng)論 3 398
  • 文/潘曉璐 我一進(jìn)店門裸影,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人军熏,你說我怎么就攤上這事轩猩。” “怎么了荡澎?”我有些...
    開封第一講書人閱讀 167,755評(píng)論 0 360
  • 文/不壞的土叔 我叫張陵均践,是天一觀的道長。 經(jīng)常有香客問我摩幔,道長彤委,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 59,528評(píng)論 1 296
  • 正文 為了忘掉前任热鞍,我火速辦了婚禮葫慎,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘薇宠。我一直安慰自己偷办,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,526評(píng)論 6 397
  • 文/花漫 我一把揭開白布澄港。 她就那樣靜靜地躺著椒涯,像睡著了一般。 火紅的嫁衣襯著肌膚如雪回梧。 梳的紋絲不亂的頭發(fā)上废岂,一...
    開封第一講書人閱讀 52,166評(píng)論 1 308
  • 那天,我揣著相機(jī)與錄音狱意,去河邊找鬼湖苞。 笑死,一個(gè)胖子當(dāng)著我的面吹牛详囤,可吹牛的內(nèi)容都是我干的财骨。 我是一名探鬼主播,決...
    沈念sama閱讀 40,768評(píng)論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼藏姐,長吁一口氣:“原來是場噩夢(mèng)啊……” “哼隆箩!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起羔杨,我...
    開封第一講書人閱讀 39,664評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤捌臊,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后兜材,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體理澎,經(jīng)...
    沈念sama閱讀 46,205評(píng)論 1 319
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡逞力,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,290評(píng)論 3 340
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了矾端。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片掏击。...
    茶點(diǎn)故事閱讀 40,435評(píng)論 1 352
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖秩铆,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情灯变,我是刑警寧澤殴玛,帶...
    沈念sama閱讀 36,126評(píng)論 5 349
  • 正文 年R本政府宣布,位于F島的核電站添祸,受9級(jí)特大地震影響滚粟,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜刃泌,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,804評(píng)論 3 333
  • 文/蒙蒙 一凡壤、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧耙替,春花似錦亚侠、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,276評(píng)論 0 23
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至铜幽,卻和暖如春滞谢,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背除抛。 一陣腳步聲響...
    開封第一講書人閱讀 33,393評(píng)論 1 272
  • 我被黑心中介騙來泰國打工狮杨, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人到忽。 一個(gè)月前我還...
    沈念sama閱讀 48,818評(píng)論 3 376
  • 正文 我出身青樓橄教,卻偏偏與公主長得像,于是被迫代替她去往敵國和親绘趋。 傳聞我的和親對(duì)象是個(gè)殘疾皇子颤陶,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,442評(píng)論 2 359

推薦閱讀更多精彩內(nèi)容