iPhone, method returns an objective-c object with a +1 retain count
I kind of understand why I'm getting this analyzer warning. Because I'm using an object that is being passed in. I've tried autorelease
and retain
however these cause me other problems like unrecognized selector sent to instance
.
The aim of my CommonUI function is to re-use code, but I have to cate开发者_如何学编程r for addSubView
and presentModalViewController
.
Perhaps I'm doing some obvious wrong ?
Change your code like this:
HelpViewController *helpvc = [[HelpViewController alloc] init....];
[vw addSubview:helpvc.view];
[helpcv release];
I think you don't need to pass the other VC.
There are two problems here.
First, if you call [vc release]
(as the other answers suggest), you'll certainly make the analyzer happy but likely crash the app. A view controller's view doesn't retain the controller, so any button targets in the view will be pointing to garbage.
You will need to somehow keep the HelpViewController
retained for as long as it is showing up onscreen. The "parent" view controller should likely retain it somehow. You could autorelease it, and return it. Then whomever calls showHelpClick...
would retain the returned controller.
Second, you don't need to have the (UIViewController *)vc
passed in as an argument.
精彩评论