ipad開發(fā)(顯示圖片和文字)

創(chuàng)建一個(gè)繼承于UITableViewController的控制器和繼承于UIViewController(綁定xib)的控制器

@class DetailViewController,RootTableViewController;@interface AppDelegate : UIResponder@property (strong, nonatomic) UIWindow *window;

//詳情界面

@property(nonatomic,strong)DetailViewController *detailVC;

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

@property(nonatomic,strong)RootTableViewController *rootVC;

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

@property(nonatomic,strong)UISplitViewController *spiltVC;

___________________________________________________________________________________________

#import "AppDelegate.h"

#import "RootTableViewController.h"

#import "DetailViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

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

// Override point for customization after application launch.

self.rootVC = [[RootTableViewController alloc] initWithStyle:UITableViewStylePlain];

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

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

self.detailVC = [[DetailViewController alloc] init];

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

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

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

self.spiltVC = [[UISplitViewController alloc] init];

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

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

self.spiltVC.delegate = self.detailVC;

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

self.window.rootViewController = self.spiltVC;

return YES;

}

_________________________________________________________________________________________

RootTableViewController.m

#import "RootTableViewController.h"

#import "AppDelegate.h"

#import "DetailViewController.h"

@interface RootTableViewController ()

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

@property(nonatomic,strong)NSArray *imgTitleArr;

// 圖片數(shù)組

@property(nonatomic,strong)NSArray *imgArr;

@end

@implementation RootTableViewController

- (void)viewDidLoad {

[super viewDidLoad];

self.imgTitleArr = @[@"圖片1",@"圖片2",@"圖片3",@"圖片4",@"圖片5",@"圖片6",@"圖片4"];

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

NSMutableArray *arr = [[NSMutableArray alloc] init];

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

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

UIImage *img = [UIImage imageNamed:imgName];

[arr addObject:img];

}

//

self.imgArr = [arr copy];

}

#pragma mark - Table view data source

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

return 1;

}

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

return self.imgArr.count;

}

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

static NSString *identifier = @"cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

if (cell == nil) {

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

}

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

;

return cell;

}

_________________________________________________________________________________________

拖拽xib


DetailViewController.m

#import "DetailViewController.h"#import "AppDelegate.h"#import "RootTableViewController.h"@interface DetailViewController ()@end

@implementation DetailViewController

- (void)viewDidLoad {

[super viewDidLoad];

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"主菜單" style:UIBarButtonItemStylePlain target:self action:@selector(showPopOverController:)];

AppDelegate *app = [UIApplication sharedApplication].delegate;

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

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

}

//回調(diào)方法

-(void)showPopOverController:(UIBarButtonItem *)sender

{

//? AppDelegate *app = [UIApplication sharedApplication].delegate;

RootTableViewController *rootVC = [[RootTableViewController 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(@"將要隱藏彈出視圖");

return YES;

}

- (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 = [UIApplication sharedApplication].delegate;

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

//

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

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

}

else if (displayMode == UISplitViewControllerDisplayModePrimaryOverlay)

{

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

}

else if (displayMode == UISplitViewControllerDisplayModeAllVisible)

{

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

self.navigationItem.leftBarButtonItem = nil;

}

else

{

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

}

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市铺然,隨后出現(xiàn)的幾起案子借跪,更是在濱河造成了極大的恐慌致开,老刑警劉巖杠园,帶你破解...
    沈念sama閱讀 206,126評(píng)論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件蚓炬,死亡現(xiàn)場(chǎng)離奇詭異慕淡,居然都是意外死亡盾沫,警方通過查閱死者的電腦和手機(jī)忍疾,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,254評(píng)論 2 382
  • 文/潘曉璐 我一進(jìn)店門闯传,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人卤妒,你說我怎么就攤上這事甥绿。” “怎么了荚孵?”我有些...
    開封第一講書人閱讀 152,445評(píng)論 0 341
  • 文/不壞的土叔 我叫張陵妹窖,是天一觀的道長。 經(jīng)常有香客問我收叶,道長骄呼,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 55,185評(píng)論 1 278
  • 正文 為了忘掉前任判没,我火速辦了婚禮蜓萄,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘澄峰。我一直安慰自己嫉沽,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,178評(píng)論 5 371
  • 文/花漫 我一把揭開白布俏竞。 她就那樣靜靜地躺著绸硕,像睡著了一般。 火紅的嫁衣襯著肌膚如雪魂毁。 梳的紋絲不亂的頭發(fā)上玻佩,一...
    開封第一講書人閱讀 48,970評(píng)論 1 284
  • 那天,我揣著相機(jī)與錄音席楚,去河邊找鬼咬崔。 笑死,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的垮斯。 我是一名探鬼主播郎仆,決...
    沈念sama閱讀 38,276評(píng)論 3 399
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼兜蠕!你這毒婦竟也來了扰肌?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 36,927評(píng)論 0 259
  • 序言:老撾萬榮一對(duì)情侶失蹤熊杨,失蹤者是張志新(化名)和其女友劉穎狡耻,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體猴凹,經(jīng)...
    沈念sama閱讀 43,400評(píng)論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡夷狰,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 35,883評(píng)論 2 323
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了郊霎。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片沼头。...
    茶點(diǎn)故事閱讀 37,997評(píng)論 1 333
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖书劝,靈堂內(nèi)的尸體忽然破棺而出进倍,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 33,646評(píng)論 4 322
  • 正文 年R本政府宣布,位于F島的核電站态蒂,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏垂蜗。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,213評(píng)論 3 307
  • 文/蒙蒙 一解幽、第九天 我趴在偏房一處隱蔽的房頂上張望贴见。 院中可真熱鬧,春花似錦躲株、人聲如沸片部。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,204評(píng)論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽档悠。三九已至,卻和暖如春望浩,著一層夾襖步出監(jiān)牢的瞬間辖所,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,423評(píng)論 1 260
  • 我被黑心中介騙來泰國打工曾雕, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留奴烙,地道東北人助被。 一個(gè)月前我還...
    沈念sama閱讀 45,423評(píng)論 2 352
  • 正文 我出身青樓剖张,卻偏偏與公主長得像切诀,于是被迫代替她去往敵國和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子搔弄,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,722評(píng)論 2 345

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