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

imageView setFrame in table view

iphone ios

I want to place my image in location (10,10,60,60). I write the code but image display from corner. The code [cell.imageView setFrame:CGRectMake(10,10,60,60)]; has no effect.