【发布时间】:2014-01-21 16:35:46
【问题描述】:
我有两个数组,其中一个是 tweets 数组并包含 twitter 推文。另一个是 instapics 数组,包含 Instagram 图片。这两个数组都有不同的日期键。推特有created_at,Instagram 有created_time。我想将它们都显示在一个 UITableView 上,并按日期组织它们。到目前为止,这是我正在做的事情,但是问题在于它只显示 Instagram 图片:
- (void)sortArrayBasedOndate {
NSDateFormatter *fmtDate = [[NSDateFormatter alloc] init];
[fmtDate setDateFormat:@"yyyy-MM-dd"];
NSDateFormatter *fmtTime = [[NSDateFormatter alloc] init];
[fmtTime setDateFormat:@"HH:mm"];
totalFeed = [totalFeed sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
// 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];
}];
}
以上是我尝试在数组上组织它们的方式,以下是我尝试显示它们的方式:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
id object = [totalFeed objectAtIndex:indexPath.row];
if ([tweets containsObject:object]) {
static NSString *Twitter = @"TweetCell";
UITableViewCell *twitter = [self.tableView dequeueReusableCellWithIdentifier:Twitter];
NSDictionary *totalArray = totalFeed[indexPath.row/2];;
// Creation Code Not shown
return twitter;
}else{
static NSString *Instagram = @"InstagramCell";
UITableViewCell *instagram = [self.tableView dequeueReusableCellWithIdentifier:Instagram];
NSDictionary *entry = instaPics[indexPath.row / 2];
// Creation Code not Shown
return instagram;
}
}
【问题讨论】:
-
您的排序过程没有使用传递给它的对象;它没有正确排序数组。我不能确定,但看起来它是使用两个提要的完整创建日期进行排序的。
-
@JoshCaswell 对不起,我是 iOS 新手,你能告诉我该怎么做吗?
-
对您不了解的内容更具体。
标签: ios objective-c arrays uitableview twitter