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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

iPad 如何创建UISplitViewController应用程序

發布時間:2023/12/10 编程问答 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 iPad 如何创建UISplitViewController应用程序 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

原文摘自:UISplitViewController的使用。

?

UISplitViewController在ipad中的使用

ipad的屏幕比iphone大,所以在界面上,ipad比iphone多一個UISplitViewController,用來實現ipad在橫屏時,分兩欄顯示所需要的界面,可以一邊是目錄一邊是具體的內容。下面我將詳細的闡述UISplitViewController在ipad中的使用。

首先是創建一個工程:ipad.demo.

然后創建一個DetailViewController和RootViewController,其中RootViewController繼承UITableViewController。同事創建兩個相應的xib文件。刪除ipad_demoViewController.相應的類列表如下:

?

然后修改ipad_demoAppDelegate:

.h文件:

#import <UIKit/UIKit.h>?
#import "RootViewController.h"?
#import "DetailViewController.h"?
@class ipad_demoViewController;?

@interface ipad_demoAppDelegate : NSObject <UIApplicationDelegate> {?
??? UIWindow *window;?
???UISplitViewController *splitViewController;?
??? RootViewController *rootViewController;?
??? DetailViewController *detailViewController;?
}?

@property (nonatomic, retain) IBOutlet UIWindow *window;?
@property (nonatomic, retain) IBOutlet UISplitViewController *splitViewController;?
@property (nonatomic, retain) IBOutlet RootViewController *rootViewController;?
@property (nonatomic, retain)? IBOutlet DetailViewController *detailViewController;?
@end

.m文件:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {????
??? // Override point for customization after app launch.?
??? [window addSubview:splitViewController.view];?
??? [window makeKeyAndVisible];?

??? return YES;?
}

修改MainWindow.xib文件:

添加UISplitViewController容器:

IB中的控件和相應的事件相聯系:連接過程是按住control鍵,然后點擊ipad_demo App Delegate,連接到Split View Controller,然后選擇自定義的事件即可,最后的結果如下:

最后在把相應的容器換成自定義的容器:實現的方法是

最后的結果是:

現在我們在實現DetailViewController:

  • ? 首先修改其相應的文件:
  • ????? .h文件修改如下:

    #import <UIKit/UIKit.h>?
    @interface DetailViewController : UIViewController {?
    ???IBOutlet UILabel *lable;?
    ??? IBOutlet UISwitch *switch1;?
    ??? NSIndexPath *index;?
    }?
    -(void)deetail:(id)sender;?
    @property (nonatomic,retain) UILabel *lable;?
    @property (nonatomic,retain) UISwitch *switch1;?
    @end

    ?? .m文件修改如下:

    #import "DetailViewController.h"?
    @implementation DetailViewController?
    @synthesize lable,switch1;?
    - (void)viewDidLoad {?
    ??? [super viewDidLoad];?
    }?
    -(void)viewWillAppear:(BOOL)animated?
    {?

    }?
    -(void)deetail:(id)sender?
    {?
    ??? index=sender;?
    ??? self.lable.text=[NSString stringWithFormat:@"Row %d,section %d",[index row],[index section]];?
    ??? if ([index row]%2==0) {?
    ??????? self.switch1.on=YES;?
    ??? }else {?
    ??????? self.switch1.on=NO;?
    ??? }?
    }?
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {?
    ??? return YES;?
    }?
    - (void)didReceiveMemoryWarning {?
    ??? [super didReceiveMemoryWarning];?
    }?
    - (void)viewDidUnload {?
    ??? [super viewDidUnload];?
    ????self.lable=nil;?
    ??? self.switch1=nil;?
    }?
    - (void)dealloc {?
    ??? [self.lable release];?
    ??? [self.switch1 release];?
    ??? [super dealloc];?
    }?
    @end

    ? 2.修改相應的xib文件:

    添加相應的控件,并且相應的組建和相應的事件相關聯。

    最后我們實現RootViewController:

  • 首先修改相應的文件:
  • ??? .h文件如下:

    #import <UIKit/UIKit.h>?
    @class DetailViewController;?
    @interface RootViewController : UITableViewController {?

    ???IBOutlet DetailViewController *detailViewController;?
    }?
    @property (nonatomic,retain) DetailViewController *detailViewController;?
    @end

    .m文件如下:

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {?
    ??? // Return the number of sections.?
    ????return 2;?
    }?

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {?
    ??? // Return the number of rows in the section.?
    ????return 7;?
    }

    ?

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {?
    ??? static NSString *CellIdentifier = @"Cell";?
    ??? UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];?
    ??? if (cell == nil) {?
    ??????? cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];?
    ??? }?
    ??? // Configure the cell…?
    ??? cell.textLabel.text=[NSString stringWithFormat:@"ROW %d section %d",[indexPath row],[indexPath section]];?
    ??? return cell;?
    }

    ?

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {?
    ??? // Navigation logic may go here. Create and push another view controller.?
    ??? // DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];?
    ??? // [self.navigationController pushViewController:detailViewController animated:YES];?
    ??? // [detailViewController release];?
    ???[detailViewController deetail:indexPath];?
    }

    2、修改相應的xib文件:

    相應的事件和控件相聯系。

    運行結果如下:

    總結

    以上是生活随笔為你收集整理的iPad 如何创建UISplitViewController应用程序的全部內容,希望文章能夠幫你解決所遇到的問題。

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