Featured post
ios - Very simple iPhone App crashes on UILabel settext -
i have simple application. have button , label in ib. have ibaction onclick calls settext on label. there's outlet label. connected in ib. crashes app first time in simulator. when launch again, sets text. crashes again next time. crashes on actual device. should simple, i'm not sure i'm doing wrong.
thanks.
in .h file :
#import <uikit/uikit.h> @interface untitledviewcontroller : uiviewcontroller { iboutlet uilabel *label; iboutlet uibutton *button; } @property (nonatomic, retain) uilabel *label; -(ibaction) onclick1: (id) sender; @end
and in .m:
- (ibaction) onclick1: (id) sender { //[label settext:@"hello world!"]; label.text = @"hello world!"; //[button settitle:@"clicked" forstate:uicontrolstatenormal]; }
sorry, i'm new site. how crash log , stack? thanks.
edit : while answer technically correct, doesn't answer question @ :( sorry
< warning - guess >
if you're getting crash setting label's text tells me have set value label in past it's not been retained correctly.
i'm guessing have code :
label = [[[uilabel alloc] initwithframe:cgrectmake(0,0,10,10)] autorelease];
when should have code like
// option 1 self.label = [[[uilabel alloc] initwithframe:cgrectmake(0,0,10,10)] autorelease];
or
// option 2 label = [[uilabel alloc] initwithframe:cgrectmake(0,0,10,10)];
( first 1 uses property retain label. second 1 doesn't autorelease it. first 1 recommended way )
- Get link
- X
- Other Apps
Comments
Post a Comment