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
loadinfomethod in a generic class which is a subclass ofNSView, sayMyGenericView. Both yourview1andview2classes would then subclass from that generic class and inherit theloadinfomethod.In case you want to divert from the implementation of
loadinfoin your base class, you can override it partially by doing (in view1 or view2):… or:
… or override completely by doing:
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
View1andView2and the method would beloadInfo.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.