I want to use – (void)drawRect:(CGRect)rect to manage some nice output to UIViewController. That for I’ve created a UIView subclass. Now I can output a picture to UIViewController. Now I’ve faced a problem how to pass to UIView subclass an object that contains all the data needed for topics, texts etc.., and this object was created in UIViewController class.
I do create the object this way:
- (void)viewDidLoad
{
self.setQualityButton.hidden=YES;
//[self setTheItem:theItem];
[drawItemDetails setTheItem:theItem]; //drawItemDetails is my UIView subclass
//theItem is an object I've retained from TableView and it's not empty
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
In drawItemDetails( UIView subclass):
-(void)setTheItem:(ItemShow*)inputTheItem;
{
if(theItem!=inputTheItem)
{
[theItem release];
theItem=inputTheItem;
[theItem retain];
}
[self setNeedsDisplay];
NSLog(@"%@",theItem.itemYear); //output null
}
What’s wrong and does this data-pass approach makes cense at all?
Passing data to the view like that is fine — you’re doing approximately the same thing you’d do if you were setting the text of a UILabel.
What you seem to be doing with your custom view’s
-drawRect:sounds weird/wrong, though. Any view’s-drawRect:should draw the view in the context that has been set up for it, and that’s it. It shouldn’t care about the view controller, try to pass data to other objects, etc. If you tell us more about what you’re trying to accomplish, we can probably offer better alternatives.