2016-12-30 2 views
0

Ich habe Comet Chat-Funktionalität in meiner Anwendung integriert. Ich verwende eine benutzerdefinierte Benutzeroberfläche für den Gruppen- und OneOnOne-Chat. Es läuft alles gut, aber das Problem ist, dass meine Anwendung nicht mehr reagiert, wenn ich zu meinem Gruppen-Chat-Bildschirm gehe. Es reagiert nicht mehr, wenn ich meinen Tisch scrolle.Comet Chat iOS nicht reagierende UI Problem

Ich hatte Versand Funktionalität in meinem CellforRowatIndexPath zum Abrufen der Bilder Link und zeigt sie. Dafür verwende ich SdWebImage Framework.

Hier ist mein Code:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *cellIdentifier = @"chatroomchatviewcell"; 
    chatViewCell = [chatTable dequeueReusableCellWithIdentifier:cellIdentifier]; 

    if (chatViewCell == nil) { 
     chatViewCell = [[ChatRoomChatViewCellSDK alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; 
    } 
    else { 
      dispatch_queue_t concurrentQueue1 = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0); 
     dispatch_async(concurrentQueue1, ^{ 

     for (UIView *view in chatViewCell.contentView.subviews) { 
      [view removeFromSuperview]; 
     } 
     }); 
    } 

    /* Define maximum contraints */ 
    CGSize constraints = CGSizeMake(((self.view.frame.size.width)*2/3 + 8.0f),100000); 
    CGFloat wrapperViewX = 0.0f; 
    CGFloat wrapperViewWidth = 0.f; 
    CGFloat wrapperViewHeight = 0.f; 

    NSString *messageString = nil; 

    if ([[[messageArray objectAtIndex:indexPath.row] objectForKey:MESSAGE] isKindOfClass:[NSString class]]) { 

     messageString = [NSString stringWithFormat:@"%@",[[messageArray objectAtIndex:indexPath.row] objectForKey:MESSAGE]]; 
    } 
    NSString *nameString = nil; 
    NSString *messageType = [NSString stringWithFormat:@"%@",[[messageArray objectAtIndex:indexPath.row] objectForKey:MESSAGE_TYPE_KEY]]; 

    UIView *wrapperView = [UIView new]; 
    UITextView *textView = [UITextView new]; 
    UIImageView *imageView = [UIImageView new]; 
    UILabel *nameLabel = [UILabel new]; 
    UILabel *timeLabel = [UILabel new]; 

    wrapperView.layer.cornerRadius = 5 ; 
    wrapperView.clipsToBounds = YES; 

    /* If message is sent by you add Me as the name */ 
    if ([[NSString stringWithFormat:@"%@",[[messageArray objectAtIndex:indexPath.row] objectForKey:@"fromid"]] isEqualToString:[NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:LOGGED_IN_USER]]]) { 

     nameString = @"Me:"; 

    } else { 
     /* Else append BuddyName in message */ 
     nameString = [NSString stringWithFormat:@"%@:",[[[messageArray objectAtIndex:indexPath.row] objectForKey:FROM] capitalizedString]]; 
    } 

    [nameLabel setFont:[UIFont systemFontOfSize:14.f]]; 
    [nameLabel setNumberOfLines:0]; 
    [nameLabel setLineBreakMode:NSLineBreakByWordWrapping]; 
    NSDictionary *attributesName = [NSDictionary dictionaryWithObjectsAndKeys: [UIFont systemFontOfSize:14.f], NSFontAttributeName, nil]; 
    CGRect nameRect = [nameString boundingRectWithSize:constraints options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading) attributes:attributesName context:nil]; 
    CGSize sizeName = nameRect.size; 
    [nameLabel setText:nameString]; 
    attributesName = nil; 

    [nameLabel setFrame:CGRectMake(4.f, 4.f, sizeName.width, sizeName.height)]; 
    [wrapperView addSubview:nameLabel]; 
    if ([messageType isEqualToString:MESSAGE_TYPE_IMAGE]) { 
     UIButton *btnclk = [UIButton new]; 
     btnclk.frame=CGRectMake(4.f, 4.f, 100, 100); 
     [btnclk setTitle:@"" forState:UIControlStateNormal]; 
     btnclk.tag=indexPath.row; 
     [btnclk addTarget:self action:@selector(ShowFullImageVIew:) 
     forControlEvents:UIControlEventTouchUpInside]; 
     dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0); 

     //this will start the image loading in bg 
     CGRect imageRect = CGRectMake(4.f, (nameLabel.frame.origin.y + nameLabel.frame.size.height + 4.f), 100.f, 100.f); 
     [imageView setFrame:imageRect]; 
     dispatch_async(concurrentQueue, ^{ 
      NSURL *imgUrl = [NSURL URLWithString:messageString]; 

      //this will set the image when loading is finished 

      dispatch_async(dispatch_get_main_queue(), ^{ 
       if (messageString == nil) { 

        [imageView setImage:[UIImage imageWithData:[[messageArray objectAtIndex:indexPath.row] objectForKey:MESSAGE]]]; 

       } else { 
        if ([[NSFileManager defaultManager] fileExistsAtPath:messageString]) { 

         [imageView setImage:[UIImage imageWithContentsOfFile:messageString]]; 
        } else { 
         UIActivityIndicatorView *activityIndicator; 
         activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; 
         activityIndicator.color = [UIColor redColor]; 

         activityIndicator.center = imageView.center; 

         [imageView addSubview:activityIndicator]; 
         [self.view bringSubviewToFront:activityIndicator]; 

         [activityIndicator startAnimating]; 


         [imageView sd_setImageWithURL:imgUrl completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { 
          [activityIndicator removeFromSuperview];        
         }]; 
        } 
       } 
      }); 
     }); 





     [wrapperView addSubview:imageView]; 
     [wrapperView addSubview:btnclk]; 

     if ([[NSString stringWithFormat:@"%@",[[messageArray objectAtIndex:indexPath.row] objectForKey:@"fromid"]] isEqualToString:[NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:LOGGED_IN_USER]]]) { 

      if (imageView.frame.size.width > nameLabel.frame.size.width) { 

       wrapperViewX = self.view.frame.size.width - imageView.frame.size.width - 14.f; 
      } else { 
       wrapperViewX = self.view.frame.size.width - nameLabel.frame.size.width - 14.f; 
      } 

     } else { 
      wrapperViewX = 7.f; 
     } 

     if (imageView.frame.size.width > nameLabel.frame.size.width) { 

      wrapperViewWidth = 4.f + imageView.frame.size.width + 4.f; 
     } else { 
      wrapperViewWidth = 4.f + nameLabel.frame.size.width + 4.f; 
     } 

     wrapperViewHeight = imageView.frame.origin.y + imageView.frame.size.height + 4.f; 

    } else if ([messageType isEqualToString:MESSAGE_TYPE_STICKER]) { 

     CGRect imageRect = CGRectMake(4.f, (nameLabel.frame.origin.y + nameLabel.frame.size.height + 4.f), 100.f, 100.f); 

     if (messageString == nil) { 

      [imageView setImage:[UIImage imageWithData:[[messageArray objectAtIndex:indexPath.row] objectForKey:MESSAGE]]]; 

     } else { 

      [imageView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"StickersFramework.bundle/%@",messageString]]]; 

     } 

     [imageView setFrame:imageRect]; 
     [wrapperView addSubview:imageView]; 

     if ([[NSString stringWithFormat:@"%@",[[messageArray objectAtIndex:indexPath.row] objectForKey:@"fromid"]] isEqualToString:[NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:LOGGED_IN_USER]]]) { 

      if (imageView.frame.size.width > nameLabel.frame.size.width) { 

       wrapperViewX = self.view.frame.size.width - imageView.frame.size.width - 14.f; 
      } else { 
       wrapperViewX = self.view.frame.size.width - nameLabel.frame.size.width - 14.f; 
      } 

     } else { 
      wrapperViewX = 7.f; 
     } 

     if (imageView.frame.size.width > nameLabel.frame.size.width) { 

      wrapperViewWidth = 4.f + imageView.frame.size.width + 4.f; 
     } else { 
      wrapperViewWidth = 4.f + nameLabel.frame.size.width + 4.f; 
     } 

     wrapperViewHeight = imageView.frame.origin.y + imageView.frame.size.height + 4.f; 

    } else { 

     [textView setFont:[UIFont systemFontOfSize:14.0f]]; 
     [textView setTextContainerInset:UIEdgeInsetsZero]; 
     [textView setBackgroundColor:[UIColor clearColor]]; 

     /* Disable scroll and editing */ 
     [textView setEditable:NO]; 
     [textView setScrollEnabled:NO]; 

     NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init]; 
     [paragraph setLineSpacing:2.0f]; 
     NSDictionary *attributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys: [UIFont systemFontOfSize:14.f], NSFontAttributeName,paragraph ,NSParagraphStyleAttributeName,nil]; 

     [messageString boundingRectWithSize:constraints options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading) attributes:attributesDictionary context:nil]; 

     [textView setText:messageString]; 

     CGSize sizeMessage = [textView sizeThatFits:constraints]; 

     textView.frame = CGRectMake(0.0f,(nameLabel.frame.origin.y + nameLabel.frame.size.height + 4.f), sizeMessage.width, sizeMessage.height); 

     [wrapperView addSubview:textView]; 

     if ([[NSString stringWithFormat:@"%@",[[messageArray objectAtIndex:indexPath.row] objectForKey:@"fromid"]] isEqualToString:[NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:LOGGED_IN_USER]]]) { 

      if (textView.frame.size.width > nameLabel.frame.size.width) { 

       wrapperViewX = self.view.frame.size.width - textView.frame.size.width - 14.f; 
      } else { 
       wrapperViewX = self.view.frame.size.width - nameLabel.frame.size.width - 14.f; 
      } 

     } else { 
      wrapperViewX = 7.f; 
     } 

     if (textView.frame.size.width > nameLabel.frame.size.width) { 

      wrapperViewWidth = 4.f + textView.frame.size.width + 4.f; 

     } else { 
      wrapperViewWidth = 4.f + nameLabel.frame.size.width + 4.f; 
     } 


     wrapperViewHeight = textView.frame.origin.y + textView.frame.size.height + 4.f; 

     attributesDictionary = nil; 
    } 

    [wrapperView setFrame:CGRectMake(wrapperViewX, 7.f, wrapperViewWidth, wrapperViewHeight)]; 


    /* Define timeString & timeLabel */ 
    NSTimeInterval _interval; 
    NSDate *date; 

    if ([[NSString stringWithFormat:@"%@",[[messageArray objectAtIndex:indexPath.row] objectForKey:@"sent"]] length] > 10) { 

     _interval = ([[NSString stringWithFormat:@"%@",[[messageArray objectAtIndex:indexPath.row] objectForKey:@"sent"]] doubleValue]/1000); 
     date = [NSDate dateWithTimeIntervalSince1970:_interval]; 

    } else { 

     _interval = ([[NSString stringWithFormat:@"%@000",[[messageArray objectAtIndex:indexPath.row] objectForKey:@"sent"]] doubleValue]/1000); 
     date = [NSDate dateWithTimeIntervalSince1970:_interval]; 

    } 

    NSDateFormatter *_formatter = [[NSDateFormatter alloc] init]; 
    [_formatter setLocale:[NSLocale currentLocale]]; 
    _formatter.dateStyle = NSDateFormatterMediumStyle; 
    _formatter.timeStyle = NSDateFormatterShortStyle; 
    _formatter.doesRelativeDateFormatting = YES; 

    NSString *timeString = [_formatter stringFromDate:date]; 

    [timeLabel setFont:[UIFont systemFontOfSize:10.f]]; 
    [timeLabel setTextColor:[UIColor colorWithRed:103.0f/255.0f green:103.0f/255.0f blue:103.0f/255.0f alpha:1.0]]; 
    [timeLabel setNumberOfLines:0]; 
    [timeLabel setLineBreakMode:NSLineBreakByWordWrapping]; 
    NSDictionary *attributesTime = [NSDictionary dictionaryWithObjectsAndKeys: [UIFont systemFontOfSize:10.f], NSFontAttributeName, nil]; 
    CGRect timeRect = [timeString boundingRectWithSize:constraints options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading) attributes:attributesTime context:nil]; 
    CGSize sizeTime = timeRect.size; 
    [timeLabel setText:timeString]; 


    if ([[NSString stringWithFormat:@"%@",[[messageArray objectAtIndex:indexPath.row] objectForKey:@"fromid"]] isEqualToString:[NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:LOGGED_IN_USER]]]) { 

     [nameLabel setTextColor:[UIColor whiteColor]]; 
     [textView setTextColor:[UIColor whiteColor]]; 
     [wrapperView setBackgroundColor:[UIColor colorWithRed:49.0f/255.0f green:140.0f/255.0f blue:231.0f/255.0f alpha:1.0f]]; 

     [wrapperView setBackgroundColor:[UIColor colorWithRed:49.0f/255.0f green:140.0f/255.0f blue:231.0f/255.0f alpha:1.0f]]; 

     [timeLabel setFrame:CGRectMake(self.view.frame.size.width - sizeTime.width - 7.f, (wrapperView.frame.origin.y + wrapperView.frame.size.height + 2.f), sizeTime.width, sizeTime.height)]; 

    } else { 


     [wrapperView setBackgroundColor:[UIColor colorWithRed:235.0f/255.0f green:235.0f/255.0f blue:235.0f/255.0f alpha:1.f]]; 

     [wrapperView setBackgroundColor:[UIColor colorWithRed:235.0f/255.0f green:235.0f/255.0f blue:235.0f/255.0f alpha:1.f]]; 

     [timeLabel setFrame:CGRectMake(7.f, (wrapperView.frame.origin.y + wrapperView.frame.size.height + 2.f), sizeTime.width, sizeTime.height)]; 
    } 
    [chatViewCell.contentView addSubview:wrapperView]; 
    [chatViewCell.contentView addSubview:timeLabel]; 
    return chatViewCell; 
} 

Hier bin ich Umsetzung Chat-Funktion für diese müssen wir die Chat-Nachrichten auf dem Bildschirm aktualisieren und für das ich verwende NsPostNotifictaionCenter. Ich lade meine Tabelle auch mit dem Versand neu, um das Problem der nicht reagierenden Benutzeroberfläche zu vermeiden. Hier poste ich den Code:

- (void)chatRoomMessageUpdateNotifier: (NSNotification *)notification { 


     dispatch_queue_t concurrentQueue1 = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0); 
     dispatch_async(concurrentQueue1, ^{ 

      if ([[[notification userInfo] objectForKey:@"TAG"] isEqualToString:@"0"]) { 
       messageArray = [NSMutableArray new]; 
       [messageArray removeAllObjects]; 
       messageArray = [[notification userInfo] objectForKey:@"data"]; 

       if ([messageArray count] > 0) { 
        dispatch_async(dispatch_get_main_queue(), ^{ 

         [chatTable reloadData]; 

        }); 



       } 

      } 
     }); 

} 

Ich weiß nicht, was ich falsch mache. Das Hauptproblem hier ist, dass meine Benutzeroberfläche nicht mehr reagiert. Alle Ideen sind herzlich willkommen.

Antwort

0

Bitte verwenden Sie den folgenden Code. Wenn Sie weiterhin Probleme haben, können Sie ein Support-Ticket anfordern https://my.cometchat.com/tickets und unser Team wird Ihnen gerne weiter helfen.

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    static NSString *cellIdentifier = @"chatroomchatviewcellsdk"; 
    chatViewCell = [chatTable dequeueReusableCellWithIdentifier:cellIdentifier]; 

    if (chatViewCell == nil) { 
     chatViewCell = [[ChatRoomChatViewCellSDK alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; 
    } 
    else { 
     for (UIView *view in chatViewCell.contentView.subviews) { 
      [view removeFromSuperview]; 
     } 
    } 

    /* Define maximum contraints */ 
    CGSize constraints = CGSizeMake(((self.view.frame.size.width)*2/3 + 8.0f),100000); 
    CGFloat wrapperViewX = 0.0f; 
    CGFloat wrapperViewWidth = 0.f; 
    CGFloat wrapperViewHeight = 0.f; 

    NSString *messageString = nil; 

    if ([[[messageArray objectAtIndex:indexPath.row] objectForKey:MESSAGE] isKindOfClass:[NSString class]]) { 

     messageString = [NSString stringWithFormat:@"%@",[[messageArray objectAtIndex:indexPath.row] objectForKey:MESSAGE]]; 
    } 

    NSString *nameString = nil; 
    NSString *messageType = [NSString stringWithFormat:@"%@",[[messageArray objectAtIndex:indexPath.row] objectForKey:MESSAGE_TYPE_KEY]]; 

    UIView *wrapperView = [UIView new]; 
    UITextView *textView = [UITextView new]; 
    UIImageView *imageView = [UIImageView new]; 
    UILabel *nameLabel = [UILabel new]; 
    UILabel *timeLabel = [UILabel new]; 

    wrapperView.layer.cornerRadius = 5 ; 
    wrapperView.clipsToBounds = YES; 

    /* If message is sent by you add Me as the name */ 
    if ([[NSString stringWithFormat:@"%@",[[messageArray objectAtIndex:indexPath.row] objectForKey:@"fromid"]] isEqualToString:[NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:LOGGED_IN_USER]]]) { 

     nameString = @"Me:"; 

    } else { 
     /* Else append BuddyName in message */ 
     nameString = [NSString stringWithFormat:@"%@:",[[[messageArray objectAtIndex:indexPath.row] objectForKey:FROM] capitalizedString]]; 
    } 

    [nameLabel setFont:[UIFont systemFontOfSize:14.f]]; 
    [nameLabel setNumberOfLines:0]; 
    [nameLabel setLineBreakMode:NSLineBreakByWordWrapping]; 
    NSDictionary *attributesName = [NSDictionary dictionaryWithObjectsAndKeys: [UIFont systemFontOfSize:14.f], NSFontAttributeName, nil]; 
    CGRect nameRect = [nameString boundingRectWithSize:constraints options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading) attributes:attributesName context:nil]; 
    CGSize sizeName = nameRect.size; 
    [nameLabel setText:nameString]; 
    attributesName = nil; 

    [nameLabel setFrame:CGRectMake(4.f, 4.f, sizeName.width, sizeName.height)]; 
    [wrapperView addSubview:nameLabel]; 


    if ([messageType isEqualToString:MESSAGE_TYPE_IMAGE]) { 

     CGRect imageRect = CGRectMake(4.f, (nameLabel.frame.origin.y + nameLabel.frame.size.height + 4.f), 100.f, 100.f); 

     if (messageString == nil) { 

      [imageView setImage:[UIImage imageWithData:[[messageArray objectAtIndex:indexPath.row] objectForKey:MESSAGE]]]; 

     } else { 
      if ([[NSFileManager defaultManager] fileExistsAtPath:messageString]) { 

       [imageView setImage:[UIImage imageWithContentsOfFile:messageString]]; 
      } else { 
       [imageView setImageWithURL:[NSURL URLWithString:messageString] placeholderImage:[UIImage imageNamed:@"default_avatar_thumbnail"] options:0 andResize:imageRect.size withContentMode:UIViewContentModeScaleAspectFill]; 
      } 
     } 

     [imageView setFrame:imageRect]; 
     [wrapperView addSubview:imageView]; 

     if ([[NSString stringWithFormat:@"%@",[[messageArray objectAtIndex:indexPath.row] objectForKey:@"fromid"]] isEqualToString:[NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:LOGGED_IN_USER]]]) { 

      if (imageView.frame.size.width > nameLabel.frame.size.width) { 

       wrapperViewX = self.view.frame.size.width - imageView.frame.size.width - 14.f; 
      } else { 
       wrapperViewX = self.view.frame.size.width - nameLabel.frame.size.width - 14.f; 
      } 

     } else { 
      wrapperViewX = 7.f; 
     } 

     if (imageView.frame.size.width > nameLabel.frame.size.width) { 

      wrapperViewWidth = 4.f + imageView.frame.size.width + 4.f; 
     } else { 
      wrapperViewWidth = 4.f + nameLabel.frame.size.width + 4.f; 
     } 

     wrapperViewHeight = imageView.frame.origin.y + imageView.frame.size.height + 4.f; 

    } else if ([messageType isEqualToString:MESSAGE_TYPE_STICKER]) { 

     CGRect imageRect = CGRectMake(4.f, (nameLabel.frame.origin.y + nameLabel.frame.size.height + 4.f), 100.f, 100.f); 

     if (messageString == nil) { 

      [imageView setImage:[UIImage imageWithData:[[messageArray objectAtIndex:indexPath.row] objectForKey:MESSAGE]]]; 

     } else { 

      [imageView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"StickersFramework.bundle/%@",messageString]]]; 

     } 

     [imageView setFrame:imageRect]; 
     [wrapperView addSubview:imageView]; 

     if ([[NSString stringWithFormat:@"%@",[[messageArray objectAtIndex:indexPath.row] objectForKey:@"fromid"]] isEqualToString:[NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:LOGGED_IN_USER]]]) { 

      if (imageView.frame.size.width > nameLabel.frame.size.width) { 

       wrapperViewX = self.view.frame.size.width - imageView.frame.size.width - 14.f; 
      } else { 
       wrapperViewX = self.view.frame.size.width - nameLabel.frame.size.width - 14.f; 
      } 

     } else { 
      wrapperViewX = 7.f; 
     } 

     if (imageView.frame.size.width > nameLabel.frame.size.width) { 

      wrapperViewWidth = 4.f + imageView.frame.size.width + 4.f; 
     } else { 
      wrapperViewWidth = 4.f + nameLabel.frame.size.width + 4.f; 
     } 

     wrapperViewHeight = imageView.frame.origin.y + imageView.frame.size.height + 4.f; 

    } else { 

     [textView setFont:[UIFont systemFontOfSize:14.0f]]; 
     [textView setTextContainerInset:UIEdgeInsetsZero]; 
     [textView setBackgroundColor:[UIColor clearColor]]; 

     /* Disable scroll and editing */ 
     [textView setEditable:NO]; 
     [textView setScrollEnabled:NO]; 

     NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init]; 
     [paragraph setLineSpacing:2.0f]; 
     NSDictionary *attributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys: [UIFont systemFontOfSize:14.f], NSFontAttributeName,paragraph ,NSParagraphStyleAttributeName,nil]; 

     [messageString boundingRectWithSize:constraints options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading) attributes:attributesDictionary context:nil]; 

     [textView setText:messageString]; 

     CGSize sizeMessage = [textView sizeThatFits:constraints]; 

     textView.frame = CGRectMake(0.0f,(nameLabel.frame.origin.y + nameLabel.frame.size.height + 4.f), sizeMessage.width, sizeMessage.height); 

     [wrapperView addSubview:textView]; 

     if ([[NSString stringWithFormat:@"%@",[[messageArray objectAtIndex:indexPath.row] objectForKey:@"fromid"]] isEqualToString:[NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:LOGGED_IN_USER]]]) { 

      if (textView.frame.size.width > nameLabel.frame.size.width) { 

       wrapperViewX = self.view.frame.size.width - textView.frame.size.width - 14.f; 
      } else { 
       wrapperViewX = self.view.frame.size.width - nameLabel.frame.size.width - 14.f; 
      } 

     } 
     else { 
      wrapperViewX = 7.f; 
     } 

     if (textView.frame.size.width > nameLabel.frame.size.width) { 

      wrapperViewWidth = 4.f + textView.frame.size.width + 4.f; 

     } else { 
      wrapperViewWidth = 4.f + nameLabel.frame.size.width + 4.f; 
     } 


     wrapperViewHeight = textView.frame.origin.y + textView.frame.size.height + 4.f; 

     attributesDictionary = nil; 
    } 

    [wrapperView setFrame:CGRectMake(wrapperViewX, 7.f, wrapperViewWidth, wrapperViewHeight)]; 


    /* Define timeString & timeLabel */ 
    NSTimeInterval _interval; 
    NSDate *date; 

    if ([[NSString stringWithFormat:@"%@",[[messageArray objectAtIndex:indexPath.row] objectForKey:@"sent"]] length] > 10) { 

     _interval = ([[NSString stringWithFormat:@"%@",[[messageArray objectAtIndex:indexPath.row] objectForKey:@"sent"]] doubleValue]/1000); 
     date = [NSDate dateWithTimeIntervalSince1970:_interval]; 

    } else { 

     _interval = ([[NSString stringWithFormat:@"%@000",[[messageArray objectAtIndex:indexPath.row] objectForKey:@"sent"]] doubleValue]/1000); 
     date = [NSDate dateWithTimeIntervalSince1970:_interval]; 

    } 

    NSDateFormatter *_formatter = [[NSDateFormatter alloc] init]; 
    [_formatter setLocale:[NSLocale currentLocale]]; 
    _formatter.dateStyle = NSDateFormatterMediumStyle; 
    _formatter.timeStyle = NSDateFormatterShortStyle; 
    _formatter.doesRelativeDateFormatting = YES; 

    NSString *timeString = [_formatter stringFromDate:date]; 

    [timeLabel setFont:[UIFont systemFontOfSize:10.f]]; 
    [timeLabel setTextColor:[UIColor colorWithRed:103.0f/255.0f green:103.0f/255.0f blue:103.0f/255.0f alpha:1.0]]; 
    [timeLabel setNumberOfLines:0]; 
    [timeLabel setLineBreakMode:NSLineBreakByWordWrapping]; 
    NSDictionary *attributesTime = [NSDictionary dictionaryWithObjectsAndKeys: [UIFont systemFontOfSize:10.f], NSFontAttributeName, nil]; 
    CGRect timeRect = [timeString boundingRectWithSize:constraints options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading) attributes:attributesTime context:nil]; 
    CGSize sizeTime = timeRect.size; 
    [timeLabel setText:timeString]; 

    if ([[NSString stringWithFormat:@"%@",[[messageArray objectAtIndex:indexPath.row] objectForKey:@"fromid"]] isEqualToString:[NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:LOGGED_IN_USER]]]) { 

     [nameLabel setTextColor:[UIColor whiteColor]]; 
     [textView setTextColor:[UIColor whiteColor]]; 
     [wrapperView setBackgroundColor:[UIColor colorWithRed:49.0f/255.0f green:140.0f/255.0f blue:231.0f/255.0f alpha:1.0f]]; 

     [wrapperView setBackgroundColor:[UIColor colorWithRed:49.0f/255.0f green:140.0f/255.0f blue:231.0f/255.0f alpha:1.0f]]; 

     [timeLabel setFrame:CGRectMake(self.view.frame.size.width - sizeTime.width - 7.f, (wrapperView.frame.origin.y + wrapperView.frame.size.height + 2.f), sizeTime.width, sizeTime.height)]; 


    } 
    else { 

     [wrapperView setBackgroundColor:[UIColor colorWithRed:235.0f/255.0f green:235.0f/255.0f blue:235.0f/255.0f alpha:1.f]]; 

     [wrapperView setBackgroundColor:[UIColor colorWithRed:235.0f/255.0f green:235.0f/255.0f blue:235.0f/255.0f alpha:1.f]]; 

     [timeLabel setFrame:CGRectMake(7.f, (wrapperView.frame.origin.y + wrapperView.frame.size.height + 2.f), sizeTime.width, sizeTime.height)]; 

    } 


    [chatViewCell.contentView addSubview:wrapperView]; 
    [chatViewCell.contentView addSubview:timeLabel]; 


    return chatViewCell; 
} 
+0

Ich habe versucht, ur-code, aber es immer noch einfrieren .. entfernt alle abteilungen. Gefolgt ur code, aber es immer noch happening – Prakash

+0

Vielen Dank für Ihre Hilfe, Mike D! Wenn Sie ein Unternehmen sind und ein Stack Overflow-Konto zwischen Mitarbeitern teilen, ist es besser, wenn Sie über individuelle Konten verfügen. Das liegt hauptsächlich daran, dass wir Fragen und Antworten bevorzugen, die nicht unterschrieben werden müssen - dieses Material wird oft von Redakteuren zugeschnitten (siehe meine Änderungen). – halfer