Xcode所有视图的动态加载的GUI [英] Xcode Dynamically loaded GUI for all views

查看:146
本文介绍了Xcode所有视图的动态加载的GUI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Xcode和Objective C是一个新的东西。



我已经成功地在我的一个视图上加载了所有的GUI对象。



现在我想重复相同的动态加载的内容到我的所有或大部分的意见..



我有一个方法在主视图如下:

   - (void)loadinfo:(id)sender {
//所有动态加载的内容等等。
}

我目前有主视图调用这个方法。 / p>

  [self loadinfo]; 

现在我需要知道(没有复制和粘贴到我的所有视图的方法)调用方法从主视图到其他视图?



我希望这一切都有意义。



编辑



我更熟悉PHP,所以如果我是做同样的事情在php我会做一个名为functions.php文件,文件到所有页面中...是否是相同的概念?

解决方案

在PHP。在Objective C中,一个对象。要在对象之间共享行为(您的PHP函数,在Objective C中称为方法),您需要将该行为插入到类层次结构中。

因此,对于您的特定情况,在一个通用类中实现 loadinfo 方法,该类是 NSView 的子类,例如 MyGenericView 。您的 view1 view2 类将从该通用类继承子类并继承 loadinfo 方法。



如果你想从你的基础中实现 loadinfo 类,可以通过执行(在view1或view2中)部分覆盖它:

   - (void)loadview {
[super loadview]; //执行默认实现
[self doSomethingDifferint]; // perform subclass specific stuff
}

...或:

   - (void)loadview {
[self doSomethingDifferint]; //执行子类特定的东西
[super loadview]; //执行默认实现
}

...或完全覆盖: / p>

   - (void)loadview {
[self doSomethingCompletelyDifferent]; //执行子类特定的东西
}

当在Objective C中命名你的类和方法时,遵循CamelCase标准,因此你的类将是 View1 View2 loadInfo



此外,您可能需要阅读一般的OO原则和Objective C 的具体方面,语言的优势及其功能。


I am reasonably new to Xcode and Objective C.

I have successfully loaded all of the GUI objects on one of my views dynamically..

Now i want to repeat the same dynamically loaded content onto all or most of my views..

I have a method in the main view like this:

-(void)loadinfo:(id)sender{
//All dynamically loaded content etc..
}

I currently have the main view calling this method like so.

[self loadinfo];

So now i need to know (without copying and pasting the method into all of my views) how to call the method from the main view into other views?

I hope this all makes sense.

Edit

I am more knowledgeable in PHP so if i was to do the same thing in php i would make a file called functions.php and include that file into all of the pages.. Is it the same concept?

解决方案

The concept is different from the approach you find with functions in PHP. In Objective C one works with objects. To share behavior (your PHP functions, called methods in Objective C) between objects you need to slot that behavior somewhere into your class hierarchy.

So for your specific case you would implement the loadinfo method in a generic class which is a subclass of NSView, say MyGenericView. Both your view1 and view2 classes would then subclass from that generic class and inherit the loadinfo method.

In case you want to divert from the implementation of loadinfo in your base class, you can override it partially by doing (in view1 or view2):

- (void) loadview {
  [super loadview]; // perform the default implementation
  [self doSomethingDifferint]; // perform subclass specific stuff
}

... or:

- (void) loadview {
  [self doSomethingDifferint]; // perform subclass specific stuff
  [super loadview]; // perform the default implementation
}

... or override completely by doing:

- (void) loadview {
  [self doSomethingCompletelyDifferent]; // perform subclass specific stuff
}

Just on a side note: it's good practice to follow CamelCase standards when naming your classes and methods in Objective C, so your classes would be View1 and View2 and the method would be loadInfo.

Further, you might want to read up on generic OO principles and Objective C's specific aspects of it to take full advantage of the language and its features.

这篇关于Xcode所有视图的动态加载的GUI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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