我是一名新程序员,正在尝试使用每个具有 dateTimeString 属性的对象对 NSMutableArray 进行排序,我正在使用此 Array 在表格视图上显示。
代码:
-(void)newAssignment:(AssignmentInfo *)assignment
{
[self.alist addObject:assignment];
NSString *filePath = [self dataFilePath];
[NSKeyedArchiver archiveRootObject:self.alist toFile:filePath];
[self.tableView reloadData];
}
- (IBAction)addTheInfo:(id)sender {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
dateFormatter.timeZone = [NSTimeZone defaultTimeZone];
dateFormatter.timeStyle = NSDateFormatterShortStyle;
dateFormatter.dateStyle = NSDateFormatterShortStyle;
NSString *dateTimeString = [dateFormatter stringFromDate: dateTimePicker.date];
self.assignmentInfo.className = self.className.text;
self.assignmentInfo.assignmentTitle = self.assignmentTitle.text;
self.assignmentInfo.assignmentDescription = self.assignmentDescription.text;
self.assignmentInfo.dateTimeString = dateTimeString;
[self presentMessage:self.assignmentInfo.description];
[self dismissViewControllerAnimated:YES completion:nil];
[self.otherdelegate newAssignment:self.assignmentInfo];
NSLog(@"%@",self.otherdelegate);
if (self.edit) {
[self.otherdelegate deletedAssignment:self.assignmentEditing];
}
}
对象中的属性:
@property (nonatomic,strong)NSString *className;
@property (nonatomic,strong)NSString *assignmentDescription;
@property (nonatomic,strong)NSString *assignmentTitle;
@property (nonatomic,strong)NSString *dateTimeString;
@property (nonatomic)bool notifcationStatus;
我需要按 dateTimeString 排序