1

我有一个带有多个视图控制器的 iPhone 应用程序,在所有视图控制器的标题中都很常见。我不想使用相同的方法并在所有控制器中创建通用视图。所以我的问题是我如何在所有控制器中使用这个通用视图。

4

3 回答 3

2

分配新视图控制器时使用 initWithNibNamed:"name of your xib"。这很简单。

于 2012-07-18T10:01:43.067 回答
1

相同,但我们可以避免定义变量 -

[self.view addSubview:[[(NavAppAppDelegate *)[[UIApplication sharedApplication] delegate] headerview] view]];
于 2012-11-03T17:05:52.617 回答
0

好的,所以您必须在 Application Delegate 中创建一次。在.h

@property(nonatomic,strong) uiviewcontroller headerview;

@synthesize headerview=_headerview;

然后在appdelegate的“didFinishLaunchingWithOptions”中将其分配为单例

self.headerview = [[headerview alloc] initWithNibName:@"headerview" bundle:nil];

所以每次你想把它添加到你的视图中。导入后从您的类中的应用程序委托创建对象。

applicationdelegate app = [uiapplication sharedapplication]delegate];
[self.view addsubview:app.headerview.view];
于 2012-07-18T10:26:53.043 回答