简体   繁体   English

在iOS 4.2中查看渲染

[英]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. 如果直接在设备上编译该应用程序会很好用,但是在创建ipa文件并通过iTunes安装该文件时,在iOS 4.2中,聊天气泡的高度超出了所需的大小,并导致了聊天气泡重叠。 But it is working fine in iOS 5.What would be the reason for this?Thanks in advance. 但这在iOS 5中运行良好,这是什么原因呢?

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: 编辑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. 是破裂的气泡图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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