组织多个视图的代码 - Objective-c

时间:2013-08-20 15:54:45

标签: objective-c

我正在创建一个启动菜单启动的ipad应用程序,它有5个选项(按钮)。这5个中的每一个都有一个菜单和其他按钮。基本上它是很多页面(UIVIews)和它的很多代码。我总是在同一个文件中写下所有内容。

我的问题是,如果每个页面都有一个单独的文件,我将如何将它们相互连接?谢谢

编辑:

我尝试将UIView的子类与ViewController连接起来,如下所示:

UIView的子类:

@implementation MyView
- (void)commonMethod:(id)sender
{
    NSLog(@"hej");
}

ViewController.h:

#import "MyView.m";

ViewController.m:

@implementation ViewController
- (void)viewDidLoad
{
    MyView *mv = [[MyView alloc] init];
    [mv CommonMethod:self];
}

我收到此错误:

d "/Users/tonymichaelsen/Library/Developer/Xcode/DerivedData/3D-shaped_2-   geccnqnxajtjkvblfiasmfippyhx/Build/Products/Debug-iphoneos/3D-shaped 2.app/3D-shaped 2" normal armv7
cd "/Users/tonymichaelsen/Documents/documents/Xcode-projects/3D-shaped 2"
setenv IPHONEOS_DEPLOYMENT_TARGET 6.0
setenv PATH   "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang    -arch armv7 -isysroot   /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhone OS6.1.sdk -L/Users/tonymichaelsen/Library/Developer/Xcode/DerivedData/3D-shaped_2- geccnqnxajtjkvblfiasmfippyhx/Build/Products/Debug-iphoneos - F/Users/tonymichaelsen/Library/Developer/Xcode/DerivedData/3D-shaped_2-  geccnqnxajtjkvblfiasmfippyhx/Build/Products/Debug-iphoneos -filelist   "/Users/tonymichaelsen/Library/Developer/Xcode/DerivedData/3D-shaped_2- geccnqnxajtjkvblfiasmfippyhx/Build/Intermediates/3D-shaped 2.build/Debug-iphoneos/3D-shaped    2.build/Objects-normal/armv7/3D-shaped 2.LinkFileList" -dead_strip -fobjc-arc -fobjc-link- runtime -miphoneos-version-min=6.0 -framework UIKit -framework Foundation -framework  CoreGraphics -o "/Users/tonymichaelsen/Library/Developer/Xcode/DerivedData/3D-shaped_2-g   eccnqnxajtjkvblfiasmfippyhx/Build/Products/Debug-iphoneos/3D-shaped 2.app/3D-shaped 2"


duplicate symbol _OBJC_CLASS_$_Cube in:
/Users/tonymichaelsen/Library/Developer/Xcode/DerivedData/3D-shaped_2-  geccnqnxajtjkvblfiasmfippyhx/Build/Intermediates/3D-shaped 2.build/Debug-iphoneos/3D-shaped      .build/Objects-normal/armv7/ViewController.o
/Users/tonymichaelsen/Library/Developer/Xcode/DerivedData/3D-shaped_2- geccnqnxajtjkvblfiasmfippyhx/Build/Intermediates/3D-shaped 2.build/Debug-iphoneos/3D-shaped  2.build/Objects-normal/armv7/Cube.o
duplicate symbol _OBJC_METACLASS_$_Cube in:
/Users/tonymichaelsen/Library/Developer/Xcode/DerivedData/3D-shaped_2-   geccnqnxajtjkvblfiasmfippyhx/Build/Intermediates/3D-shaped 2.build/Debug-iphoneos/3D-shaped   2.build/Objects-normal/armv7/ViewController.o
/Users/tonymichaelsen/Library/Developer/Xcode/DerivedData/3D-shaped_2-  geccnqnxajtjkvblfiasmfippyhx/Build/Intermediates/3D-shaped 2.build/Debug-iphoneos/3D-shaped   2.build/Objects-normal/armv7/Cube.o
ld: 2 duplicate symbols for architecture armv7

1 个答案:

答案 0 :(得分:2)

  

我可以为每个页面分别创建一个文件吗?

当然,这取决于你。每个视图后面可以有一个不同的视图控制器,或者几个视图可以共享一个视图控制器。 Xcode让您可以完全控制自己想要做的事情,让您指定屏幕背后的类。

  

我如何将它们彼此连接?

最简单的连接方法可能是storyboard segues,因为它可以让你根本不写代码。所有的连接和交互都将由Cocoa的故事板基础设施在幕后处理。您需要做的就是将按钮连接到实际工作中。