iphone - iOS error: 'message sent to dealllocated instance', when trying to change label -
so goal trying achieve when click on button, change text of label. following tutorials online, , trying myriad of alternative memory alloc/release, still can't past error: *** -[homeviewcontroller performselector:withobject:withobject:]: message sent deallocated instance 0x4b4aa10
here's code:
in app delegate:
- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions { // override point customization after application launch. self.homeviewcontroller = [[homeviewcontroller alloc] initwithnibname:@"homeviewcontroller" bundle:[nsbundle mainbundle]]; self.window.rootviewcontroller = self.homeviewcontroller; //[window addsubview:self.homeviewcontroller.homeview]; [self.window makekeyandvisible]; return yes; } - (void)dealloc { [homeviewcontroller release]; [window release]; [super dealloc]; } then in homeviewcontroller.m:
@synthesize btnnewproject; @synthesize btnopenproject; @synthesize label; - (ibaction)newproject:(id)sender { nsstring *text = @"we did it!"; label.text = text; //[text release]; } - (void)viewdidunload { [super viewdidunload]; // release retained subviews of main view. // e.g. self.myoutlet = nil; //self.homeview = nil; } - (void)dealloc { [label release]; [btnopenproject release]; [btnnewproject release]; //[homeview release]; [super dealloc]; } so event fires , newproject called, can't past crash. i've tried autoreleasing controller, , other things. there glaring mistakes?
thank you!
update:
so using ib. have setup connections properly, think, homeviewcontroller (whose class have set under custom class), buttons , label, , actions buttons.
one important detail have view on top of view controller (and it's connected file's owner), , buttons , label on top of view in ib, connections through homeviewcontroller - not sure if should matter. don't set view anywhere in code (ie. in app delegate controller set up), variable within homeviewcontroller, declared (without alloc) other variables (buttons , label):
@interface homeviewcontroller : uiviewcontroller { homeview *homeview; uibutton *btnnewproject; uibutton *btnopenproject; uilabel *label; } @property (nonatomic, retain) homeview *homeview; @property (nonatomic, retain) iboutlet uibutton *btnnewproject; @property (nonatomic, retain) iboutlet uibutton *btnopenproject; @property (nonatomic, retain) iboutlet uilabel *label; - (ibaction)openproject:(id)sender; - (ibaction)newproject:(id)sender; @end here screenshot of connections: 
hmm... going pick @ allocations little more...
i have uploaded project here: http://devmu.com/transfer/notemap.zip
okay, i've downloaded , taken @ project. you're getting mixed view controllers being objects in interface builder. it's area apple documentation lacking in, in opinion. you're better off book learning part.
the objects in interface builder actual objects created, initialised, , placed iboutlets when nib loads. have homeviewcontroller in nib. allocating , initialising homeviewcontroller in code in app delegate. need 1 or other.
i moved view out of view controller in interface builder, , deleted view controller nib. once renamed nib homeviewcontroller.xib (as homeview.h , homeview.m seem leftovers , nib corresponds homeviewcontroller, message showed when button clicked.
Comments
Post a Comment