ios - Can't set cell title's text -
i'm writing simple notes app, when seek assign title note.title got error.
-(notez*)createnotewithtitle:(nsstring*)titlenote andtext:(nsstring*)textnote { notez *newnote = [notez new]; if (!_notesarray) { _notesarray = [nsmutablearray new]; } newnote.datecreated = [nsdate new]; newnote.title = [nsstring stringwithformat:@"23"]; newnote.text = [nsstring stringwithformat:@"233"]; [_notesarray addobject:newnote]; homecoming newnote; }
notez.h : #import
@interface notez : nsobject @property nsstring *text; @property nsstring *title; @property nsdate* datecreated; -(notez*)createnotewithtitle:(nsstring*)title andtext:(nsstring*)text; -(void)save; +(instancetype)sharedmanager; -(nsarray*)sortednotes; -(void)removenoteatindex:(nsuinteger)index; @end
note.datecreated ok, note.title , note.text isn't.
they both nsstring...
- (ibaction)addnote:(id)sender { [[notez sharedmanager] createnotewithtitle:@"note title" andtext:@"note text"]; }
since declared title
, text
properties, reason exception: [notez settitle:]: unrecognized selector sent instance, apparently
i can create guess here. usually, when declaring property, setter
, getter
method it. way can omit writing these hand if have lot of instance variables on class.
using dot notation
equivalent calling setter
or getter
. in case
newnote.title = [nsstring stringwithformat:@"23"];
is equivalent to:
[newnote settitle:[nsstring stringwithformat:@"23"]];
now, exception suggests setter
method: settitle:
not exist on object. i'm not sure reason might be, seek explicitly synthesize properties.
therefor, in .m-file add together next lines of code:
@synthesize title; @synthesize text;
not sure if solve issue, hope explanation of properties
, getters
, setters
helps understand little more what's going on.
ios objective-c nsstring
No comments:
Post a Comment