Note that there are some explanatory texts on larger screens.

plurals
  1. POinitWithFrame doesnt work on my project in IOS 5 but did in IOS 4
    text
    copied!<p>I made an program from a tutorial in ios 4 which was a checkbox. I had a friend who is starting to program in xcode for iphone. So, I gave him my codes so he can start. Turns out, he was trying to do the code himself in ios5 following the code I made for IOS4. He kept telling me that his didn't work and that he got a bunch of errors some as follows. So I would open my code and ran it on my updated xcode and it ran fine, no problem what so ever. The funny thing was when I got to his house and I looked at the code and played around with it. He was right. Trying to do the code from a new project in the new xcode with the new ios, the project would throw all sorts of errors. I posted some in the bottom. </p> <p>So, my question is this... why is this? does this have to do with the the way ios5 uses ARC and different properties?</p> <ul> <li>NSObject may not respond to initWithFrame</li> <li>Instance method - setImageForState not found(return type defaults to "id")</li> <li>instance method - addTarget:action:forControlEvents not found(return type default to id)</li> <li>MicheckBox may not respond to initWithFrame and some more</li> </ul> <p>my code is as follows have to png one called checkbox_ticked.png and a checkbox_not_ticked.png</p> <p>micheckbox.h</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface MICheckBox : UIButton { BOOL isChecked; } @property (nonatomic,assign) BOOL isChecked; -(IBAction) checkBoxClicked; @end </code></pre> <p>micheckbox.m</p> <pre><code>#import "MICheckBox.h" @implementation MICheckBox @synthesize isChecked; - (id)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { [self setImage:[UIImage imageNamed:@"checkbox_not_ticked.png"] forState:UIControlStateNormal]; [self addTarget:self action:@selector(checkBoxClicked)forControlEvents:UIControlEventTouchUpInside]; } return self; } -(IBAction) checkBoxClicked { if(self.isChecked ==NO) { self.isChecked =YES; [self setImage:[UIImage imageNamed:@"checkbox_ticked.png"] forState:UIControlStateNormal]; } else { self.isChecked =NO; [self setImage:[UIImage imageNamed:@"checkbox_not_ticked.png"]forState:UIControlStateNormal]; } } - (void)dealloc { [super dealloc]; } @end </code></pre> <p>MICheckBoxAppDelegate.h</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface MICheckBoxAppDelegate : NSObject &lt;UIApplicationDelegate&gt; { UIWindow *window; } @property (nonatomic, retain) IBOutlet UIWindow *window; @end </code></pre> <p>MICheckBoxAppDelegate.m</p> <pre><code>#import "MICheckBoxAppDelegate.h" #import "MICheckBox.h" @implementation MICheckBoxAppDelegate @synthesize window; - (void)applicationDidFinishLaunching:(UIApplication *)application { // Override point for customization after application launch MICheckBox *checkBox =[[MICheckBox alloc]initWithFrame:CGRectMake(5, 80, 150, 30)]; [checkBox setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; [checkBox setTitle:@"Checkbox" forState:UIControlStateNormal]; [window addSubview:checkBox]; [window makeKeyAndVisible]; } - (void)dealloc { [window release]; [super dealloc]; } @end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload