Reputation: 25
After researching and looking around - I'm lost with an issue.
Eventually I'm on the wrong track, so please bear with me in case I try to approach it totally wrong.
I've got a tableview in which each Cell can contain a unique view matching the subject (representing an icon so to speak).
I've got all my icons setup as custom UIView classes and draw them using the drawRect method. Right now I have a placeholder UIView in the Storyboard which I fish out with the assigned tag. The custom UIView subclass get's all it's size information to draw itself from the placeholder view.
My code would look like this:
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath{
UIView *eventIndicatorView = (UIView*)[cell viewWithTag:10000];
if (conditionMatched){
eventIndicatorView = ??? Qestion: How to assign the matching subclass of UIVIew ??? ;
}
[eventIndicatorView setNeedsDisplay];
}
I can get it to work by adding all possible UIViews on top of each other, hide them all and just unhide them based on the condition. Yet I'm not so sure that's really the best way to go.
Any help would be very much appreciated.
An answer like: "Why don't you do just this or that" leads back to the question: Because right now I don't know any better. So I'd like to apologise in advance.
Upvotes: 1
Views: 116
Reputation: 10615
Well you can't replace a view on the storyboard, the best course of action for you is to create your custom UIView
that matches the condition with same width/height as placeholder view and then add it to the placeholder as subview.
Here is how you can do that:
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath{
UIView *eventIndicatorView = (UIView*)[cell viewWithTag:10000];
if (conditionMatched) {
MyCustomView *customView = [[MyCustomView alloc] initWithFrame:CGRectMake(0, 0, eventIndicatorView.frame.size.width, eventIndicatorView.frame.size.height)];
[eventIndicatorView addSubview:customView];
}
[eventIndicatorView setNeedsDisplay];
}
Upvotes: 2