Ios 应用程序在使用图像滚动滚动scrollview时崩溃,在ARC中接收到内存异常
我正在使用Ios 应用程序在使用图像滚动滚动scrollview时崩溃,在ARC中接收到内存异常,ios,objective-c,uiview,uiscrollview,Ios,Objective C,Uiview,Uiscrollview,我正在使用UIScrollview并添加子视图来显示消息。滚动时,会出现接收到的内存异常。15天来我一直在努力寻找这个。请帮我解决这个问题 要显示,我第一次加载了5条消息。滚动后,根据数组计数添加子视图。如果是,子视图将根据消息长度增加。如果是长消息,它将崩溃,并出现接收到的内存异常 这是我的密码 -(void)createView:(float)yAxis { // NSLog(@"Create view %f",yAxis); for (UIView * view in bac
UIScrollview
并添加子视图来显示消息。滚动时,会出现接收到的内存异常
。15天来我一直在努力寻找这个。请帮我解决这个问题
要显示,我第一次加载了5条消息。滚动后,根据数组计数添加子视图。如果是,子视图将根据消息长度增加。如果是长消息,它将崩溃,并出现接收到的内存异常
这是我的密码
-(void)createView:(float)yAxis
{
// NSLog(@"Create view %f",yAxis);
for (UIView * view in backgroundScroll.subviews) {
if (view.tag == 15) {
[view removeFromSuperview];
}
}
for(int i=0;i<[pageMessageArray count];i++)
{
UIView *backgrounf_View=[self messageChildElements:yAxis :i];
[del.msglistViewArray addObject:backgrounf_View];
UIView *backgrounf_View1= [del.msglistViewArray objectAtIndex:i];
[backgroundScroll addSubview:backgrounf_View1];
yAxis=yAxis+oldY_Axis+65;
}
CGRect contentRect = CGRectZero;
for (UIView *view in backgroundScroll.subviews)
{
contentRect = CGRectUnion(contentRect, view.frame);
}
//UIView *backgrounf_View1= [del.msglistViewArray objectAtIndex:i];
backgroundScroll.contentSize = CGSizeMake(backgroundScroll.frame.size.width, yAxis-10);
lblPermenentmessage.frame=CGRectMake(30, contentRect.size.height+20,800, 50);
//LastMessageYaxis=contentRect.size.height+20;
lblPermenentmessage.text=@"Messages are displayed for 24-48 hours and automatically deleted permanently.";
}
-(UIView *)messageChildElements:(float)yAxis :(int)index
{
// NSLog(@"Create view %f",yAxis);
communityObject *objMessage=[del.messageArray objectAtIndex:index];
UIView *backgrounf_View=nil;
UITextView *txt_Message=nil;
UIButton *btnURL =nil;
UIButton *btnAttachment=nil;
UIButton *btnDate=nil;
UIButton *btnSendBy=nil;
UIButton *btnAttachmentName=nil;
UIButton *btnSendTo=nil;
NSString *labelText = objMessage.Message;
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:labelText];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:8];
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [labelText length])];
CGFloat height=[self getNewsize:objMessage.Message :backgroundScroll.frame.size.width-30];
backgrounf_View=[[UIView alloc]initWithFrame:CGRectMake(26,yAxis,backgroundScroll.frame.size.width-30,height)];
if([objMessage.inorout isEqualToString:@"out"])
{
//ye
[backgrounf_View setBackgroundColor:[UIColor colorWithRed:251/255.0f green:247/255.0f blue:193/255.0f alpha:1.0f]];
[[backgrounf_View layer] setBorderWidth:1.0f];
[[backgrounf_View layer] setBorderColor:[UIColor colorWithRed:236/255.0f green:237/255.0f blue:178/255.0f alpha:1.0f].CGColor];
}
else
{
//[cell.lblName addTarget:self action:@selector(replayClick:) forControlEvents:UIControlEventTouchUpInside];
[backgrounf_View setBackgroundColor:[UIColor colorWithRed:251/255.0f green:215/255.0f blue:245/255.0f alpha:1.0f]];
[[backgrounf_View layer] setBorderWidth:1.0f];
[[backgrounf_View layer] setBorderColor:[UIColor colorWithRed:226/255.0f green:188/255.0f blue:218/255.0f alpha:1.0f].CGColor];
}
// backgrounf_View.autoresizingMask=UIViewAutoresizingFlexibleWidth;
backgrounf_View.layer.cornerRadius=10;
//backgrounf_View.tag=15;
backgrounf_View.clipsToBounds=YES;
backgrounf_View.tag=objMessage.indexValue;
txt_Message = [[UITextView alloc] initWithFrame:CGRectMake(12, 6, backgroundScroll.frame.size.width-40, height)];
txt_Message.backgroundColor=[UIColor redColor];
[txt_Message setScrollEnabled:NO];
[txt_Message setUserInteractionEnabled:NO];
[txt_Message setBackgroundColor:[UIColor clearColor]];
//txt_Message.autoresizingMask=UIViewAutoresizingFlexibleWidth;
txt_Message.attributedText=attributedString;
//[txt_Message sizeToFit];
if([del.device isEqualToString:@"iphone"])
{
[txt_Message setFont:[UIFont fontWithName:@"Arial" size:17]];
}
else
{
[txt_Message setFont:[UIFont fontWithName:@"Arial" size:21]];
}
[backgrounf_View addSubview:txt_Message];
oldY_Axis=height+20;
if (objMessage.Link.length>0)
{
btnURL = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btnURL.frame = CGRectMake(11,height,backgroundScroll.frame.size.width-100,40);
[btnURL setTitle:objMessage.Link forState:UIControlStateNormal];
btnURL.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
btnURL.contentVerticalAlignment = UIControlContentVerticalAlignmentTop;
// btnURL.backgroundColor=[UIColor redColor];
btnURL.tag=objMessage.indexValue;
btnURL.titleLabel.lineBreakMode=UILineBreakModeCharacterWrap;
btnURL.titleLabel.numberOfLines=2;
btnURL.titleLabel.font=[UIFont fontWithName:@"Arial" size:20];
btnURL.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
[btnURL setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[backgrounf_View addSubview:btnURL];
oldY_Axis=height+btnURL.frame.size.height+20;
}
if (objMessage.Filename.length>0)
{
btnAttachment= [UIButton buttonWithType:UIButtonTypeRoundedRect];
btnAttachment.frame = CGRectMake(11, oldY_Axis,40, 40);
btnAttachment.tag=objMessage.indexValue;
UIImage *buttonattachment=[UIImage imageNamed:@"attach.png"];
[btnAttachment setBackgroundImage:buttonattachment forState:UIControlStateNormal];
btnAttachment.userInteractionEnabled=YES;
btnAttachmentName = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btnAttachmentName.frame = CGRectMake(47,oldY_Axis+5,backgroundScroll.frame.size.width-150,60);
[btnAttachmentName setTitle:objMessage.Filename forState:UIControlStateNormal];
btnAttachmentName.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
btnAttachmentName.contentVerticalAlignment = UIControlContentVerticalAlignmentTop;
btnAttachmentName.tag=objMessage.indexValue;
btnAttachmentName.titleLabel.font=[UIFont fontWithName:@"Arial" size:20];
btnAttachmentName.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
[btnAttachmentName setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[backgrounf_View addSubview:btnAttachment];
[backgrounf_View addSubview:btnAttachmentName];
oldY_Axis=oldY_Axis+btnAttachment.frame.size.height+30;
}
btnDate = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btnDate.frame = CGRectMake(11,oldY_Axis,130,30);
[btnDate setTitle:[NSString stringWithFormat:@"%@:",objMessage.Date] forState:UIControlStateNormal];
btnDate.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
btnDate.contentVerticalAlignment = UIControlContentVerticalAlignmentTop;
btnDate.tag=objMessage.indexValue;
btnDate.titleLabel.font=[UIFont fontWithName:@"Arial" size:15];
btnDate.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
[btnDate setTitleColor:[UIColor colorWithRed:70/255.0f green:70/255.0f blue:70/255.0f alpha:1.0f] forState:UIControlStateNormal];
[backgrounf_View addSubview:btnDate];
btnSendBy = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btnSendBy.frame = CGRectMake(127,oldY_Axis,backgroundScroll.frame.size.width-50,200);
[btnSendBy setTitle:objMessage.senderPerson forState:UIControlStateNormal];
btnSendBy.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
btnSendBy.contentVerticalAlignment = UIControlContentVerticalAlignmentTop;
btnSendBy.tag=objMessage.indexValue;
// btnURL.backgroundColor=[UIColor redColor];
//btnSendBy.titleLabel.lineBreakMode=UILineBreakModeCharacterWrap;
btnSendBy.titleLabel.font=[UIFont fontWithName:@"Arial" size:15];
btnSendBy.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
[btnSendBy setTitleColor:[UIColor colorWithRed:70/255.0f green:70/255.0f blue:70/255.0f alpha:1.0f] forState:UIControlStateNormal];
[backgrounf_View addSubview:btnSendBy];
btnSendTo = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btnSendTo.frame = CGRectMake(11,oldY_Axis+25,backgroundScroll.frame.size.width-50,200);
[btnSendTo setTitle:objMessage.senderPerson forState:UIControlStateNormal];
btnSendTo.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
btnSendTo.contentVerticalAlignment = UIControlContentVerticalAlignmentTop;
// btnURL.backgroundColor=[UIColor redColor];
//btnSendBy.titleLabel.lineBreakMode=UILineBreakModeCharacterWrap;
btnSendTo.titleLabel.font=[UIFont fontWithName:@"Arial" size:15];
btnSendTo.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
[btnSendTo setTitleColor:[UIColor colorWithRed:70/255.0f green:70/255.0f blue:70/255.0f alpha:1.0f] forState:UIControlStateNormal];
[backgrounf_View addSubview:btnSendTo];
NSString *communityName=@"";
if([del.communityId isEqualToString:@"none"])
{
communityName=objMessage.Community;
communityName=[NSString stringWithFormat:@"%@: ",objMessage.Community];
}
//NSLog(@"Group type %@ and %@",objMessage.groupType,del.communityId);
if([objMessage.groupType isEqualToString:@"Personal"])
{
[btnSendTo setTitle:[NSString stringWithFormat:@"%@%@",communityName,objMessage.Person] forState: UIControlStateNormal];
}
else if([objMessage.groupType isEqualToString:@"Everyone"])
{
[btnSendTo setTitle:[NSString stringWithFormat:@"%@%@",communityName,@"Everyone"] forState: UIControlStateNormal];
}
else
{
[btnSendTo setTitle:[NSString stringWithFormat:@"%@%@",communityName,objMessage.GroupName] forState: UIControlStateNormal];
}
[btnURL addTarget:self action:@selector(getLink:) forControlEvents:UIControlEventTouchUpInside];
[btnAttachmentName addTarget:self action:@selector(fileDowload:) forControlEvents:UIControlEventTouchUpInside];
[btnAttachment addTarget:self action:@selector(fileDowload:) forControlEvents:UIControlEventTouchUpInside];
backgrounf_View.frame=CGRectMake(24,yAxis,backgroundScroll.frame.size.width-30,oldY_Axis+55);
LastMessageYaxis=backgrounf_View.frame.origin.y+backgrounf_View.frame.size.height+10;
del.RefreshValue=0;
LastValue=index;
communityObject *com=[[communityObject alloc]init];
com.MessageId=nil;
com.Date=nil;
com.Message=nil;
com.Link=nil;
com.Attachment=nil;
com.Filename=nil;
com.attachmentType=nil;
com.imageSize=nil;
com.groupType=nil;
com.Person=nil;
com.GroupName=nil;
com.senderPerson=nil;
com.Community=nil;
com.inorout=nil;
return backgrounf_View;
}
-(void)createView:(float)yAxis
{
//NSLog(@“创建视图%f”,yAxis);
用于(UIView*backgroundScroll.子视图中的视图){
如果(view.tag==15){
[视图从SuperView移除];
}
}
对于(int i=0;i0)
{
btnURL=[UIButton按钮类型为:UIButtonTypeRondRect];
btnURL.frame=CGRectMake(11,高度,背景滚动。frame.size.width-100,40);
[btnURL setTitle:objMessage.Link for状态:UIControlStateNormal];
btnURL.contentHorizontalAlignment=uicontrol内容HorizontalAlignment左侧;
btnURL.contentVerticalAlignment=uicontrol contentVerticalAlignment顶部;
//bNurl.backgroundColor=[UIColor redColor];
btnURL.tag=objMessage.indexValue;
b nurl.titleLabel.lineBreakMode=UILineBreakModeCharacterWrap;
b数字标题标签numberOfLines=2;
btnURL.titleLabel.font=[UIFont fontWithName:@“Arial”大小:20];
btnURL.contentEdgeInsets=UIEdgeInsetsMake(0,0,0,0);
[btnURL SETTITLECLOR:[UIColor blackColor]用于状态:UIControlStateNormal];
[背景视图添加子视图:btnURL];
旧轴=高度+数字框架.尺寸.高度+20;
}
if(objMessage.Filename.length>0)
{
btnAttachment=[UIButton按钮类型:UIButtonTypeRondRect];
btnatachment.frame=CGRectMake(11,旧轴,40,40);
btnatachment.tag=objMessage.indexValue;
UIImage*buttonattachment=[UIImage ImageName:@“attach.png”];
[btnatachment setBackgroundImage:buttonattachment for状态:uicontrol状态正常];
btnatachment.userInteractionEnabled=YES;
btNatAttachmentName=[UIButton Button,类型:UIButtonTypeRondRect];
btnatachmentname.frame=CGRectMake(47,旧_轴+5,背景滚动。frame.size.width-150,60);
[btnAttachmentName setTitle:objMessage.Filename for状态:UIControlStateNormal];
btnAttachmentName.contentHorizontalAlignment=uicontrol内容HorizontalAlignment左;
btnAttachmentName.contentVerticalAlignment=UIControlContentVerticalAlignmentTop;
btnatachmentname.tag=objMessage.indexValue;
btnatachmentname.titleLabel.font=[UIFont fontWithName:@“Arial”大小:20];
btnatachmentname.contentEdgeInsets=UIEdgeInsetsMake(0,0,0,0);
[btnAttachmentName setTitleColor:[UIColor blackColor]用于状态:UIControlStateNormal];
[背景视图添加子视图:b附加];
[背景视图添加子视图:btnatachmentname];
旧轴=旧轴+附件.框架.尺寸.高度+30;
}
btnDate=[UIButton按钮类型:UIButtonTypeRoundRect];
btnDate.frame=CGRectMake(11,旧轴,130,30);
[BTN数据集标题:[NSString stringWithFormat:@“%@:,objMessage.Date]用于状态:UIControlStateNormal];
btnDate.contentHorizontalAlignment=uicontrol内容HorizontalAlignment左侧;
btnDate.contentVerticalAlignment=uicontrolContentVerticalAlignment顶部;
btnDate.tag=objMessage.indexValue;
btnDate.titleLabel.font=[UIFont fontWithName:@“Arial”大小:15];
btnDate.contentEdgeInsets=UIEdgeInsetsMake(0,0,0,0);
[B数据设置标题颜色:[UIColor COLOR WITH RED:70/255.0f绿色:70/255.0f蓝色:70/255.0f alpha:1.0f]用于状态:UIControlStateNormal];
[背景视图添加子视图:b数据];
btnSendBy=[UIButton按钮类型为:UIButtonTypeRondRect];
btnSendBy.frame=CGRectMake(127,oldY_轴,backgroundScroll.frame.size.width-50200);
[btnSendBy setTitle:objMessage.senderPerson for状态:UIControlStateNormal];
btnSendBy.contentHorizontalAlignment=uicontrol内容HorizontalAlignment左侧;
btnSendBy.contentVerticalAlignment=uicontrol内容垂直对齐顶部;
btnSendBy.tag=objMessage.indexValue;
//bNurl.backgroundColor=[UIColor redColor];
//btnSendBy.titleLabel.lineBreakMode=UILineBreakModeCharacterWrap;
btnSendBy.titleLabel.font=[UIFont fontWithName:@“Arial”大小:15];
btnSendBy.contentEdgeInsets=UIEdgeInsetsMake(0,0,0,0);
[btnSendBy setTitleColor:[UIColor color with red:70/255.0f green:70/255.0f blue:70/255.0f alpha:1.0f]用于状态:UIControlStateNormal];
[背景视图添加子视图:btnSendBy];
btnSendTo=[UIButton按钮类型为:UIButtonTypeRondRect];
btnSendTo.frame=CGRectMake(11,oldY_轴+25,backgroundScroll.frame.size.width-50200);
[btnSendTo setTitle:objMessage.senderPerson for状态:UIControlStateNormal];
btnSendTo.contentHorizontalAlignment=uicontrol内容HorizontalAlignment左侧;
btnSendTo.contentVerticalAlignment=uicontrolContentVerticalAlignment顶部;
//bNurl.backgroundColor=[UIColor redColor];
//btnSendBy.titleLabel.lineBreakMode=UILineBreakModeCharacterWrap;
btnSendTo.titleLabel.font=[UIFont fontWithName:@“Arial”大小:15];
btnSendTo.contentEdgeInsets=UIEdgeInsetsMake(0,0,0,0);
[btnSendTo setTitleColor:[UIColor color with red:70/255.0f green:70/255.0f blue:70/255.0f alpha:1.0f]用于状态:UIControlStateNormal];
[背景视图添加子视图:btnSendTo];
NSString*communityName=@;
如果([del.communityId IsequalString:@“none”])
{
communityName=objMessage.Community;
communityName=[NSString stringWithFormat:@“%@:,objMessage.Community];
}
//NSLog(@“组类型%@和%@”,objMessage.groupType,del.communityId);
if([objMessage.groupType isEqualToString:@“Personal”])
{
[BTN发送到s
for (UIView * view in backgroundScroll.subviews) {
if (view.tag == 15) {
[view removeFromSuperview];
}
}