objective c - ios5 - "EXC_BAD_ACCESS" when clicking button -
i total beginner objective c.
currently try display view in main window. view contains button. reason clicking button xcode throws error.
hopefully can me understand doing wrong.
- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions{ self.window = [[uiwindow alloc] initwithframe:[[uiscreen mainscreen] bounds]]; // override point customization after application launch. self.window.backgroundcolor = [uicolor whitecolor]; btnview *btn = [[btnview alloc] init]; [self.window addsubview:btn.view]; [self.window makekeyandvisible]; return yes; } the viewcontroller of button view has action recognizing touch event h file:
- (ibaction)touched:(id)sender; and in m file
- (ibaction)touched:(id)sender { //actions ... } by touching button following error:
whats wrong?
m file:

h file: 
i assume have arc enabled project.
when return didfinishlaunchingwithoptions: object assigned btn released since assign local variable defined within method. make btnview *btn strong property of class , should stay around handle button presses. (remember use self.btn in references it.)
(but, i'm curious, why not put button on main view in first place , not worry controller , subviews?)
Comments
Post a Comment