【发布时间】:2014-11-06 15:55:47
【问题描述】:
我正在编写简单的笔记应用程序,但是当我尝试将标题分配给 note.title 时出现错误。
-(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];
return newNote;
}
Notez.h: #导入
@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 可以,但是 note.title 和 note.text 不行。
它们都是 NSString...
- (IBAction)addNote:(id)sender {
[[Notez sharedManager] createNoteWithTitle:@"Note Title" andText:@"Note Text"];
}
【问题讨论】:
-
并且不要在 cmets 中添加更多细节。使用附加代码和信息更新您的问题。
-
@Greg 不,只需使用
= @"23";。 -
你到底有什么错误?
-
可能不是这个评论的地方,但是我觉得这个类的结构真的很不常规。您应该考虑将
createNoteWithTitle:andText:变成类方法而不是实例方法。就目前而言,您可以在任何实例上调用它(不仅仅是您的sharedManager.. 顺便说一句,它根本不是经理)。 -
有些东西你没有给我们看。
标签: ios objective-c nsstring