ios之UISplitViewController
iPad的屏幕比iPhone大,所以在界面上,iPad比iPhone多一个UISplitViewController,用来实现iPad在横屏时,分两栏显示所需要的界面,可以一边是目录一边是具体的内容。下面我将详细的阐述UISplitViewController在ipad中的使用。
首先是创建一个工程:iPad.demo.
<IGNORE_JS_OP style="WIDOWS: 2; TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,255,255); TEXT-INDENT: 0px; FONT: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; WORD-WRAP: break-word; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: rgb(68,68,68); WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">
然后创建一个DetailViewController和RootViewController,其中RootViewController继承UITableViewController。同事创建两个相应的xib文件。删除ipad_demoViewController.相应的类列表如下:
<IGNORE_JS_OP style="WIDOWS: 2; TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,255,255); TEXT-INDENT: 0px; FONT: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; WORD-WRAP: break-word; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: rgb(68,68,68); WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">
然后修改ipad_demoAppDelegate:
.h文件:
.m文件:
修改MainWindow.xib文件:
添加UISplitViewController容器:
<IGNORE_JS_OP style="WIDOWS: 2; TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,255,255); TEXT-INDENT: 0px; FONT: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; WORD-WRAP: break-word; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: rgb(68,68,68); WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">
IB中的控件和相应的事件相联系:连接过程是按住control键,然后点击ipad_demo App Delegate,连接到Split View Controller,然后选择自定义的事件即可,最后的结果如下:
<IGNORE_JS_OP style="WIDOWS: 2; TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,255,255); TEXT-INDENT: 0px; FONT: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; WORD-WRAP: break-word; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: rgb(68,68,68); WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">
最后在把相应的容器换成自定义的容器:实现的方法是
<IGNORE_JS_OP style="WIDOWS: 2; TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,255,255); TEXT-INDENT: 0px; FONT: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; WORD-WRAP: break-word; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: rgb(68,68,68); WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">
最后的结果是:
<IGNORE_JS_OP style="WIDOWS: 2; TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,255,255); TEXT-INDENT: 0px; FONT: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; WORD-WRAP: break-word; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: rgb(68,68,68); WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">
现在我们在实现DetailViewController:
首先修改其相应的文件:
.h文件修改如下:
.m文件修改如下:
2.修改相应的xib文件:
添加相应的控件,并且相应的组建和相应的事件相关联。
<IGNORE_JS_OP style="WIDOWS: 2; TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,255,255); TEXT-INDENT: 0px; FONT: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; WORD-WRAP: break-word; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: rgb(68,68,68); WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">
最后我们实现RootViewController:
首先修改相应的文件:
.h文件如下:
.m文件如下:
2、修改相应的xib文件:
相应的事件和控件相联系。
<IGNORE_JS_OP style="WIDOWS: 2; TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,255,255); TEXT-INDENT: 0px; FONT: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; WORD-WRAP: break-word; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: rgb(68,68,68); WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">
运行结果如下:
<IGNORE_JS_OP style="WIDOWS: 2; TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,255,255); TEXT-INDENT: 0px; FONT: 14px/21px Tahoma, 'Microsoft Yahei', Simsun; WORD-WRAP: break-word; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: rgb(68,68,68); WORD-SPACING: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">
源代码: http://easymorse-iphone.googlecode.com/svn/trunk/ipad.demo/