简体   繁体   中英

View rendering in iOS 4.2

I built a custom view to make chat messages according to this tutorial

It is working fine if the app is directly compiled on device.But while creating an ipa file and installing it via iTunes, in iOS 4.2, the height of the chat bubbles are stretched more than the required size and causes overlapping of chat bubbles. But it is working fine in iOS 5.What would be the reason for this?Thanks in advance.

EDIT:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    NSDictionary *dict = (NSDictionary *)[messages objectAtIndex:indexPath.row];
    NSString *msg = [[dict objectForKey:@"message"] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    CGSize  textSize = { 260.0, 10000.0 };
    CGSize size = [msg sizeWithFont:[UIFont boldSystemFontOfSize:13]
                  constrainedToSize:textSize
                      lineBreakMode:UILineBreakModeWordWrap];

    size.height += padding*3;

    CGFloat height = size.height < 65 ? 65 : size.height;
    return height;

}

EDIT 2:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"MessageCellIdentifier";

    SMMessageViewTableCell *cell = (SMMessageViewTableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[[SMMessageViewTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }


    if ([messages count]>0) {
        NSLog(@"index path is %d",indexPath.row);

    NSDictionary *s = (NSDictionary *) [messages objectAtIndex:indexPath.row];


    NSString *sender =allTrim([s objectForKey:@"sender"]);
    NSString *senderId = [s objectForKey:@"friendId"];
    NSString *message = [s objectForKey:@"message"];
        if ([message length]<8)
        {
            message=[message stringByAppendingString:@"  "];
        }
    message=[message stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    NSString *time = [s objectForKey:@"time"];
    NSString *locatn = [s objectForKey:@"friendLocation"];

    CGSize  textSize = { 260.0, 10000.0 };
    CGSize size = [message sizeWithFont:[UIFont boldSystemFontOfSize:13]
                      constrainedToSize:textSize
                          lineBreakMode:UILineBreakModeWordWrap];

    size.width += (padding/2);

    cell.messageContentView.text = [message stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    cell.accessoryType = UITableViewCellAccessoryNone;
    cell.userInteractionEnabled = YES;
        cell.selectionStyle=UITableViewCellSelectionStyleNone;    
    UIImage *bgImage = nil;

    if ([senderId isEqualToString:UIAppDelegate.userId]) { 

        sender=@"Me";

        bgImage = [[UIImage imageNamed:@"ChatBubbleGray.png"] stretchableImageWithLeftCapWidth:24  topCapHeight:15];

        [cell.messageContentView setFrame:CGRectMake(padding, padding*2, size.width, size.height)];

        [cell.bgImageView setFrame:CGRectMake( cell.messageContentView.frame.origin.x - padding/2,
                                              cell.messageContentView.frame.origin.y - padding/2,
                                              size.width+padding,
                                              size.height+padding)];
        cell.senderAndTimeLabel.textAlignment=UITextAlignmentLeft;

    } else {


        bgImage = [[UIImage imageNamed:@"ChatBubbleGreen.png"] stretchableImageWithLeftCapWidth:24  topCapHeight:15];

        [cell.messageContentView setFrame:CGRectMake(320 - size.width - padding,
                                                     padding*2,
                                                     size.width,
                                                     size.height)];

        [cell.bgImageView setFrame:CGRectMake(cell.messageContentView.frame.origin.x - padding/2,
                                              cell.messageContentView.frame.origin.y - padding/2,
                                              size.width+padding,
                                              size.height+padding)];
        cell.senderAndTimeLabel.textAlignment=UITextAlignmentRight;


    }
    cell.bgImageView.image = bgImage;
    if ([locatn length]>0)
    {
        cell.senderAndTimeLabel.text = [NSString stringWithFormat:@"%@, %@   %@", sender, locatn, time];

    }
    cell.senderAndTimeLabel.text = [NSString stringWithFormat:@"%@,   %@", sender, time];
    }
    return cell;
}

Have you tried direct building in release? Typically direct compilation is done with out optimizations applied. I've never heard of this happening but, it's possible some optimization is wacking out your views.

I built [...] according to a tutorial

There's your first programming error. ;)

Kidding aside, running a non-debug executable causes the app to have an uninitialized, non-zeroed heap where the instance variable values are held. If you don't initialize all your instance variables, it may lead to unpredictable behavior. That may be an issue here, but we can't see all the code involved, so we can only bet on what may be wrong. And the code you did attach, doesn't seem to be the problem. It's the drawing of bubbles that's broken.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM