Ios 在TableView中按时间顺序组织单元格

Ios 在TableView中按时间顺序组织单元格,ios,uitableview,sorting,twitter,nsarray,Ios,Uitableview,Sorting,Twitter,Nsarray,我有两个UITableViewCell,每个都对应一条Twitter推特或一张Instagram图片。到目前为止,我已经将其设置为在两个单元格之间切换,并将其从Twitter推特转到Instagram图片。但是,我想组织UITableView,以便它在TableView中按时间顺序组织Twitter推特和Instagram图片。Instagram API和Twitter API的日期键都不同。Twitter API的时间键为created_at,Instagram的时间键为created_tim

我有两个UITableViewCell,每个都对应一条Twitter推特或一张Instagram图片。到目前为止,我已经将其设置为在两个单元格之间切换,并将其从Twitter推特转到Instagram图片。但是,我想组织UITableView,以便它在TableView中按时间顺序组织Twitter推特和Instagram图片。Instagram API和Twitter API的日期键都不同。Twitter API的时间键为created_at,Instagram的时间键为created_time。如何组织这两个阵列?另外,tweet和pic所在的阵列都是NSMutableArray

以下是我迄今为止尝试过的代码:

    // Setup for Cells
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {

        UITableViewCell *twitterCell = [self createTwitterCell:indexPath];
        UITableViewCell *instagramCell = [self createInstagramCell:indexPath];

        if (indexPath.row % 2 == 0) {
            return twitterCell;
        }else{
            return instagramCell;
        }

    }

   // Array Updater
    - (void)updateArrays {
        instaPics = self.timelineResponse[@"data"];
        totalFeed = [tweets arrayByAddingObjectsFromArray:instaPics];
        [self sortArrayBasedOndate:totalFeed];

    }

   // Current flawed method to organize by date
    - (void)sortArrayBasedOndate {
        NSDateFormatter *fmtDate = [[NSDateFormatter alloc] init];
        [fmtDate setDateFormat:@"yyyy-MM-dd"];

        NSDateFormatter *fmtTime = [[NSDateFormatter alloc] init];
        [fmtTime setDateFormat:@"HH:mm"];

        NSComparator compareDates = ^(id string1, id string2)
        {
            // Instagram Date Retrieval
            NSDictionary *instagram = self.instaPics;
            NSString *createdAt = instagram[@"created_time"];
            int createdAtN = [createdAt intValue];
            NSTimeInterval timestamp = (NSTimeInterval)createdAtN;
            NSDate *date1 = [NSDate dateWithTimeIntervalSince1970:timestamp];

            // Twitter Date Retrieval
            NSDictionary *twitter = self.tweets;
            NSDate *date2 = twitter[@"created_at"];

            return [date1 compare:date2];
        };

        NSSortDescriptor * sortDesc1 = [[NSSortDescriptor alloc] initWithKey:@"start_date" ascending:YES comparator:compareDates];
        [totalFeed sortUsingDescriptors:@[sortDesc1]];

    }

如果你们还需要更多的代码摘录,请随意提问:

看来你们走对了方向。你为什么不把Twitter的时间设置成与Instagram的时间相匹配的格式呢

NSComparator compareDates = ^(id string1, id string2)
    {
        // Instagram Date Retrieval
        NSDictionary *instagram = self.instaPics;
        NSString *createdAt = instagram[@"created_time"];
        int createdAtN = [createdAt intValue];
        NSTimeInterval timestamp = (NSTimeInterval)createdAtN;
        NSDate *date1 = [NSDate dateWithTimeIntervalSince1970:timestamp];

        // Twitter Date Retrieval
        NSDictionary *twitter = self.tweets;
        NSString *twitterCreated = twitter[@"created_at"];
        int createdAtTwitter = [twitterCreated intValue];
        NSTimeInterval timestampTwitter = (NSTimeInterval)createdAtTwitter;
        NSDate *date2 = [NSDate dateWithTimeIntervalSince1970:timestampTwitter];

        return [date1 compare:date2];
    };

很好,谢谢,但是我如何在UITableView中显示推文/图片?如果indexath.row%2==0{return twitterCell;}或者{return instagramCell;}则不执行此操作