【问题标题】:Issue aggregate Instagram Pics and Twitter Tweets发布聚合 Instagram 图片和 Twitter 推文
【发布时间】:2013-12-17 13:46:53
【问题描述】:

我试图通过这个声明来汇总 Instagram 和 Twitter 的两条时间线:

if (indexPath.row % 2 == 0)

但是,对于每条推文和图片,它只显示其他所有帖子。因为它显示了第一张和第三张 Instagram 图片,以及第二张和第四张 Twitter 推文。这是我创建每个单元格的代码:

if (indexPath.row % 2 == 0)  {
            static NSString *CellIdentifier = @"TweetCell";
            UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
            cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Background.png"]];

            NSDictionary *tweet = tweets[indexPath.row];

            return cell;

        }else {

            static NSString *CellIdentifier = @"InstagramCell";
            UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
            cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Background.png"]];

            NSDictionary *entry = instaPics[indexPath.row];

            return cell;
        }

}

【问题讨论】:

  • 我不认为“加重”意味着你认为它的意思。 :) 也许你的意思是“聚合”。

标签: ios iphone uitableview twitter nsdictionary


【解决方案1】:

您需要将indexPath.row 除以 2。

if (indexPath.row % 2 == 0)  {
    static NSString *CellIdentifier = @"TweetCell";
    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Background.png"]];

    NSDictionary *tweet = tweets[indexPath.row / 2];

    return cell;
} else {
    static NSString *CellIdentifier = @"InstagramCell";
    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Background.png"]];

    NSDictionary *entry = instaPics[indexPath.row / 2];

    return cell;
}

当然,这假设两个数组具有相同数量的对象。

【讨论】:

    猜你喜欢
    • 2011-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-18
    • 2021-12-31
    • 2013-08-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多