Adding item to a subview from a external class

I've created a UIView and can add things to it by using [self.topView addSubview:image]; Now I am importing a class to create a calendar which has a heap of buttons. I could put it in the same class and say [self.topView addSubview:button] but if its in another class how do I add it to the subview of the class that owns it? Hope that makes sense...


You need a reference in your external class to the class that owns the view (call it the "owner class"), and presumably write a method in your owner class to add a passed-in view to your chosen subview. Something along the lines of:

- (void) insertSubview:(UIView*)newView { 
   if (newView) [self.topView addSubview:newView];

Setting up the reference can be done a number of ways, so I'll leave that one to you.

Need Your Help

Create the sums of all possible combinations of a vector

c++ vector

I have been trying to create a program that is supposed to find all the possible combinations of numbers in a vector, and add them together, then at the end check if they match a given number. I do...