Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For your purpose you must create a new array with merging both tweets and instaPics array in single one then your all data sort as single piece. </p> <p>Merge both data array as below::</p> <pre><code>NSArray *pictureArray = [tweets arrayByAddingObjectsFromArray: instaPics]; </code></pre> <p><strong>Note ::</strong> <code>NSDictionary (NSMutableDictionary)</code> is by default sorted according to its key value. Here we sort array according to particular key of contains dictionaries </p> <p>Now sort your <strong>pictureArray</strong> as below::</p> <pre><code>NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"created_at" ascending:YES]; NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor]; pictureArray = [pictureArray sortedArrayUsingDescriptors:sortDescriptors]; </code></pre> <p>Then redefine your tableview method as ::</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *tweetsCellIdentifier = @"tweetsCell"; static NSString *instaCellIdentifier = @"instaCell"; UITableViewCell *cell = nil; BOOL tweets = NO; // Now you get dictionary that may be of tweets array or instagram array // Due to its different structure // I thinks your both dictionaries have different structure NSDictionary *pictDictionary = pictureArray[indexPath.row]; if (your_check_condition for tweets dictionary) { tweets = YES; } // Get cell according to your dictionary data that may be from tweets or instagram if (tweets) { cell = [tableView dequeueReusableCellWithIdentifier:tweetsCellIdentifier]; } else { cell = [tableView dequeueReusableCellWithIdentifier:instaCellIdentifier]; } if (cell == nil) { // Design your cell as you desired; if (tweets) { // Design cell for tweets cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:tweetsCellIdentifier]; } else { // Design cell for instagram cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:instaCellIdentifier]; } } // Write your login to get dictionary picture data // Tweets and Instagram array are merged. So get appropriate data with your logic // May be both dictionaries structure are different. so write your logic to get picture data // Fill data according tweets dict or instgram // Get cell elements in which you will show dict data i.e. images, title etc. if (tweets) { // Fill cell data for tweets } else { // Fill cell data for instagram } return cell; } </code></pre> <p>After all of above reload your tableview after getting data in pictureArray as below ..</p> <pre><code>//Reload TableView [tableView reloadData]; </code></pre> <p>It may help you.</p> <p><strong>Editted ::</strong> Edit your code as below. I modify your instgram cell creations and filling. Like this define your tweets cell design and filling data as done for instagram</p> <pre><code>NSUserDefaults *user = [NSUserDefaults standardUserDefaults]; static NSString *tweetsCellIdentifier = @"tweetsCell"; static NSString *instaCellIdentifier = @"instaCell"; UITableViewCell *cell = nil; BOOL tweets = YES; BOOL twitterLoggedIn = [user boolForKey:@"twitterLoggedIn"]; // Now you get dictionary that may be of tweets array or instagram array // Due to its different structure // I thinks your both dictionaries have different structure NSDictionary *totalFeedDictionary = totalFeed[indexPath.row]; // Get cell according to your dictionary data that may be from tweets or instagram if (tweets) { cell = [tableView dequeueReusableCellWithIdentifier:tweetsCellIdentifier]; } else { cell = [tableView dequeueReusableCellWithIdentifier:instaCellIdentifier]; } if (cell == nil) { // Design your cell as you desired; if (tweets) { // Now correct it as instagram cell design below your tweets cell design // Only create here desired elements and its define design pattern here // Don't Fill here At last already we fill it // Due to scrolling cells are reuse and must be fill all time when they come from deque cel // Design cell for tweets cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:tweetsCellIdentifier]; cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Background.png"]]; NSDictionary *tweet = totalFeed[indexPath.row]; //Set username for twitter NSString *name = [[tweet objectForKey:@"user"] objectForKey:@"name"]; UILabel *twitterNameLabel = (UILabel *)[cell viewWithTag:202]; [twitterNameLabel setFont:[UIFont fontWithName:@"Helvetica-Light" size:12.0]]; [twitterNameLabel setText:name]; //Set status for twitter NSString *text = [tweet objectForKey:@"text"]; UILabel *twitterTweetLabel = (UILabel *)[cell viewWithTag:203]; [twitterTweetLabel setFont:[UIFont fontWithName:@"Helvetica-Light" size:10.0]]; [twitterTweetLabel setText:text]; //Set Profile Pic for twitter dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSString *imageUrl = [[tweet objectForKey:@"user"] objectForKey:@"profile_image_url"]; NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrl]]; dispatch_async(dispatch_get_main_queue(), ^{ UIImageView *profilePic = (UIImageView *)[cell viewWithTag:201]; profilePic.image = [UIImage imageWithData:data]; //Make the Profile Pic ImageView Circular CALayer *imageLayer = profilePic.layer; [imageLayer setCornerRadius:25]; [imageLayer setMasksToBounds:YES]; }); }); //Set number of Favorites for Tweet NSString *favoritesCount = [[tweet objectForKey:@"user"]objectForKey:@"favourites_count"]; UIButton *favoritesButton = (UIButton *)[cell viewWithTag:204]; [favoritesButton setTitle:[NSString stringWithFormat:@" %@",favoritesCount] forState:UIControlStateNormal]; [favoritesButton setTitle:[NSString stringWithFormat:@" %@",favoritesCount] forState:UIControlStateHighlighted]; favoritesButton.titleLabel.font = [UIFont fontWithName:@"Helvetica-Light" size:12]; } else { // Design cell for instagram cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:instaCellIdentifier]; cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Background.png"]]; UIImageView *instagramImageView = [[UIImageView alloc] init]; instagramImageView.tag = 104; [cell.contentView addSubview:instagramImageView]; UILabel *instagramUserLabel = [[UILabel alloc] init]; instagramUserLabel.tag = 102; [instagramUserLabel setFont:[UIFont fontWithName:@"Helvetica-Light" size:16.0]]; [cell.contentView addSubview:instagramUserLabel]; UILabel *instagramCaptionLabel = [[UILabel alloc] init]; [instagramCaptionLabel setFont:[UIFont fontWithName:@"Helvetica-Light" size:12.0]]; instagramCaptionLabel.tag = 103; [cell.contentView addSubview:instagramCaptionLabel]; UIImageView *instagramProfilePic = [[UIImageView alloc] init]; instagramProfilePic.frame = CGRectMake(35, 31, 50, 50); instagramProfilePic.tag = 101; [cell.contentView addSubview:instagramProfilePic]; } } // Fill Data here if (tweets) { // Now correct as below your tweets cell filling // Only get here desired elements and fill them here } else { NSDictionary *entry = totalFeed[indexPath.row]; NSString *imageUrlString = entry[@"images"][@"low_resolution"][@"url"]; NSURL *url = [NSURL URLWithString:imageUrlString]; UIImageView *instagramImageView = (UIImageView *)[cell viewWithTag:104]; [instagramImageView setImageWithURL:url]; NSString *user = entry[@"user"][@"full_name"]; UILabel *instagramUserLabel = (UILabel *)[cell viewWithTag:102]; [instagramUserLabel setText:user]; UILabel *instagramCaptionLabel = (UILabel *)[cell viewWithTag:103]; if (entry[@"caption"] != [NSNull null] &amp;&amp; entry[@"caption"][@"text"] != [NSNull null]) { NSString *caption = entry[@"caption"][@"text"]; [instagramCaptionLabel setText:caption]; }else{ NSString *caption = @""; [instagramCaptionLabel setText:caption]; } NSString *imageUserPicUrl = entry[@"user"][@"profile_pic"][@"url"]; NSURL *profileURL = [NSURL URLWithString:imageUserPicUrl]; UIImageView *instagramProfilePic = (UIImageView *)[cell viewWithTag:101]; [instagramProfilePic setImageWithURL:profileURL]; } return cell; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload