Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

moonman239

Cancelled
Original poster
Mar 27, 2009
1,541
32
I have a menu view in my app. Because the layout of the menu is non-uniform and I like being able to use Interface Builder for these items, I have decided to create a UIView subclass called "MenuView" and plaster blank UIViews where the items will go.

Now, I'd like to know if there's a way to swap each UIView as they're loaded from the UIView.
 
Add outlets for the dummy views into MenuView and connect them up in IB. At run time you'll have access to do what you want, like remove them and add new ones to replace them.

Alternatively you could just loop through the MenuView subviews and remove them and then add a new varying number of views.
 
Add outlets for the dummy views into MenuView and connect them up in IB. At run time you'll have access to do what you want, like remove them and add new ones to replace them.

Alternatively you could just loop through the MenuView subviews and remove them and then add a new varying number of views.

Thanks for the suggestion.

Actually, come to think of it, perhaps I could try overriding addSubview and doing something like this:
Code:
-(void)addSubview:(UIView *)view
{
    if (viewIsCell)
    {
      MenuViewCell *cell = [[MenuViewCell alloc] initWithFrame:[view frame]];
      [super addSubview:cell];
    }
    else
    {
       [super addSubview:view];
    }
}

However, I have also been thinking about simply going with a UICollectionView and implementing a custom layout. Either way, I'll have to figure out how to make sure the app knows where the data goes.
 
You can add your MenuView objects using IB. They just won't look like their real appearance. Add UIViews and then set their custom class to your custom class.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.