0

我有一个包含多个部分的表格视图,按我的对象的属性(日期)分组我尝试根据日期的值对表格视图进行排序。我为此创建了一个函数,但出现错误:

- (void)sortObjectsDictionnary:(NSArray *)arrayObjects
{
//this is my nsdictionnary
    [objects removeAllObjects]
//this is nsmutableaaray that contains dats
    [objectsIndex removeAllObjects];

    NSMutableSet *keys = [[NSMutableSet alloc] init];

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy/MM/dd"];

    for(int i=0;i<[arrayObjects count];i++){
        Task *myTask=[arrayObjects objectAtIndex:i];

//curentsection contains my objects whith dates
            NSMutableArray *currentSection = [objects objectForKey:taskDate];

            if (currentSection == nil)
            {
                [keys addObject:taskDate];

                currentSection = [[[NSMutableArray alloc] init] autorelease];

                [objects setObject:currentSection forKey:taskDate];


            }

            // we add objet to the right section
            [currentSection addObject:myTask];

    }
    [dateFormatter release];


    for (id element in keys) 
    { 
        [objectsIndex addObject:element];

        NSMutableArray *currentSection = [objects objectForKey:element];

        //I get an error in this line
        [currentSection sortUsingSelector:@selector(compare:)];

    }
4

1 回答 1

0

您没有提到错误消息是什么,我假设错误消息可能是由于访问 NSMutableArray 数组对象而没有对其进行初始化。在 NSMutableArray *currentSection = [NSMutableArray]alloc]init] 之前尝试对数组进行分配和初始化;currentSection = [objects objectForKey:element];

    //I get an error in this line
    [currentSection sortUsingSelector:@selector(compare:)];

好吧,这纯粹是一个猜测。如果这不起作用,请发布您的错误消息。

巴拉特

于 2013-07-25T21:44:29.320 回答