设置基本的基于拆分视图的应用程序 [英] Set up a basic split-view-based application

查看:84
本文介绍了设置基本的基于拆分视图的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图为基于拆分视图的应用程序创建基础,因为在过去的几天里,我花了一段时间来研究并尝试那些不起作用,不完整或过时的教程.

I am trying to create the base for a split-view-based app, because over the last couple days, I have spent awhile looking at and trying tutorials that did not work, were incomplete, or were out of date.

在设置了基本知识之后,我应该遵循什么步骤:

What are the steps I should follow, and after I have the basics set up:

  1. 如何更改工具栏上按钮的名称?
  2. 我想包含一个弹出菜单;如何更改该菜单顶部的名称?

推荐答案

本教程适用于初学者.如果您已经在Objective-c中编码了一段时间,那么您可能会在这里学不到任何东西.

This tutorial is intended for beginners. If you have been coding in Objective-c for a while you probably won't learn anything here.

在学习完本教程之后,您将拥有一个基于拆分视图的应用程序,该应用程序具有三个(或更多)不同的视图,以及一个用于浏览应用程序的弹出菜单.

After this tutorial you will have a split-view-based app with three (or more) different views, and the popover menu for navigating your app.

第1步:获取一些Apple代码

Step 1: Getting some Apple code

从Apple获取(下载)MultiDetailsView示例代码. http://developer.apple.com/library/ios /#samplecode/MultipleDetailViews/Introduction/Intro.html

Get (download) the MultiDetailsView sample code from Apple. http://developer.apple.com/library/ios/#samplecode/MultipleDetailViews/Introduction/Intro.html

此代码为我们提供了一个基于splitview的应用程序,具有2个不同的视图.除非您不知道此示例代码存在,否则没什么大不了的.

This code provides us with a splitview-based application with 2 different views. Unless you didn't know this sample code existed, then this is no big deal.

第2步:确保一切正常

在Xcode中打开项目.生成,然后运行项目以确保一切正常.当我尝试构建和运行该应用程序时,遇到了以下错误:

Open up the project in Xcode. Build, then Run the project to insure that everything is working properly. When I tried to build and run the app, I ran into this error:

XCode could not find a valid private certificate/valid key-pair for this profile in your keychain

我意识到我的证书已经过时了(我猜这只是因为代码直接来自苹果而暴露出来了?).如果碰巧遇到相同的问题,请查看

I realized that my certificate was out of date (I am guessing that this only came to light because the code was directly from apple?). If you happen to run into the same problem, check out this thread. Alternatively you can just download the latest version from Xcode from the app store.

无论如何,如果一切正常,您应该具有以下2个视图:

Anyways, if everything is working properly, you should have the following 2 views:

第3步:添加我们自己的视图

Step 3: Adding our own views

a部分:创建文件

现在是时候添加更多视图(这可能是您想要的).

Now it is time to add some more views (which is probably what you're looking for).

转到文件->新文件...

Go to File -> New File...

如果您使用的是 Xcode 4 :选择Objective-C类,然后为子类选择UIViewController,并确保选中针对iPad为目标"和为用户界面使用XIB".

If you're using Xcode 4: Select Objective-C Class, then for subclass choose UIViewController, and insure that 'Targeted For iPad' and 'With XIB for user interface' are checked.

如果您使用的是 Xcode 3 :选择UIViewController子类,然后选中针对iPad"和针对用户界面使用XIB"

If you're using Xcode 3: Select UIViewController subclass, then check 'Targeted for iPad' and 'With XIB for user interface'

文件将出现在左侧菜单上,如果它们位于错误的位置(.h和.h应该在类下,.xib应该在资源下),则可以将它们拖到适当的目录中. ).

The files will appear on your left-hand menu, you can drag them to the appropriate directory if they're in the wrong spots (the .h and .h should be under Classes, and the .xib should be under resources).

首先,将SecondDetailViewController.h的内容复制到您的.h文件中,然后将SecondDetailViewController.m的内容复制到您的.m文件中.确保无论它最初说出SecondDetailViewController的位置如何,现在都具有您的文件名.

First, copy the contents of SecondDetailViewController.h to your .h file, and copy the contents of SecondDetailViewController.m to your .m file. Make sure that wherever it originally said SecondDetailViewController that it now has the name of your file.

我的.h文件:

我的.m文件:

b部分:RootViewController.m内容

Part b: RootViewController.m content

接下来,打开RootViewController.m

Next, open up the RootViewController.m

当前,正在导入3个原始.h文件.我们需要添加刚刚创建的一个.

Currently, the 3 original .h files are being imported. We need to add the one we've just created.

接下来,进入tableView方法,并将返回值从2更改为3.每次添加新视图时,都需要增加该数字! (即,如果您在完成本教程后添加了另一个视图,请将其更改为4).本质上,此方法仅返回您拥有的视图数.

Next, make your way down to the tableView method, and change the return value from 2 to 3. Every time you add a new view, you need to increment this number! (i.e. if you add another view after you're done this tutorial, change it to 4). Essentially, this method just returns how many views you have.

该方法下面的方法处理将在菜单中显示的内容.我们需要在此处进行一些更改.由于我们要在if/else语句中添加另一个选项,因此必须将原始else更改为if else,并且必须提供一个条件,在我们的情况下,该条件只是检查其第二行(在索引1)(indexPath.row == 1)

The method right under that handles what will be displayed in your menu. We need to do a few changes here. Since we're adding another option to the if/else statements, the original else must be changed to if else, and we must supply a condition, which in our case is just checking to see if its the second row (at index 1) (indexPath.row == 1)

下一个方法处理要显示的视图.添加另一个if语句.在第一行中,我的YourViewHereViewController为绿色,您应该使用.h/.m文件的名称.然后,在我的红色@"YourViewHereViewController"为红色的地方,您应该拥有您的.xib文件的名称.

The next method handles which view to display. Add another if statement. In the first line, where I have YourViewHereViewController in green, you should have the name of your .h / .m file. Then where I have @"YourViewHereViewController" in red, you should have the name of your .xib file.

c部分:小臂

最后但并非最不重要的一点是,我们需要处理xib文件.首先打开SecondDetailView.xib并复制视图.然后将其粘贴到您创建的.xib文件中(首先删除可能存在的所有文件).您可以通过双击文本来更改视图的标题.

Last but not least, we need to go deal with our xib file. First open up SecondDetailView.xib and copy the view. Then paste it in the .xib file you created (delete anything that might be there first). You can change the title of the view by double clicking on the text.

最后要做的是行连接.按住Control键并单击文件的所有者",然后将其拖到工具栏上,然后选择toolBar(这是RootController按钮将出现在toolBar上的方式).

Last thing to do is row connections. Control-Click Files's Owner, and drag it to the toolbar and select toolBar (this is how the RootController button will appear on the toolBar).

再次按住Control键并单击文件所有者",然后将其拖到视图中并选择视图.

Control-Click File's Owner again, then drag it to the view and select view.

如果您立即构建它,一切都会正常工作!

If you build it run now, everything should work!

这是我在此之后遇到的一些问题:

Here are some questions I had after I was at this point:

问:如何更改工具栏上按钮的名称? 答:工具栏(及其按钮)由RootViewController.m文件控制,请查找此方法

Q: How do I change the name of the button on the toolbar? A: The toolbar (and therefor button) is controlled from the RootViewController.m file, look for this method

- (void)splitViewController:(UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem*)barButtonItem forPopoverController:(UIPopoverController*)pc {

    // Keep references to the popover controller and the popover button, and tell the detail view controller to show the button.
    barButtonItem.title = @"Root View Controller";
    self.popoverController = pc;
    self.rootPopoverButtonItem = barButtonItem;
    UIViewController <SubstitutableDetailViewController> *detailViewController = [splitViewController.viewControllers objectAtIndex:1];
    [detailViewController showRootPopoverButtonItem:rootPopoverButtonItem];
}

注意barButtonItem.title = @"Root View Controller";,将@更改为您想要的任何内容!注意:如果将此字段留为空白,则该按钮将不会显示!

Note barButtonItem.title = @"Root View Controller";, change the @ to whatever you want! Note: if you leave this field blank then the button will not appear!

问:如何更改弹出菜单顶部的名称?

A:添加以下行以声明/更改名称. self.title = @"Menu";,在您的RootViewController.m文件中,在- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {方法中.

A: Add the following line to declare/change the name. self.title = @"Menu";, in your RootViewController.m file, in the - (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { method.

这篇关于设置基本的基于拆分视图的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆