我已经设置了 customcell autoresizingMask
属性的内容视图,UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin |UIViewAutoresizingFlexibleRightMargin;
它工作正常,但是当我旋转设备内容视图的屏幕时,宽度改变了,但是当我滚动表格时,contenview 的宽度发生了变化(它在委托方法 tableView 中计算大小:)tableView cellForRowAtIndexPath: indexPath
。上述一个问题和第二个问题是在滚动之后从横向旋转回纵向形式,内容视图的宽度变小。
preference* pref = [[preference alloc] init];
[pref initialize];
userInfo *mahesh=[pref getUserInfo];
NSLog(@"index of cell****** %d",indexPath.section);
static NSString *CellIdentifier = @"CustomCell2";
imTextVO *temp=[masterArray objectAtIndex:(indexPath.section)];
CustomCell2 *cell1 =(CustomCell2 *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSString *cellValue = [commonArray objectAtIndex:(indexPath.section)];
if (cell1==nil)
{
cell1 = [[CustomCell2 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
// UIImageView *image=[[UIImageView alloc] init];
//
// [cell1.contentView addSubview:image];
// if (temp.type==2)
// {
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
// button.frame=CGRectMake(110, 45, 100,40);
[button addTarget:self action:@selector(viewAttachmentOfEvent:) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"View Attachment" forState:UIControlStateNormal];
button.titleLabel.font=[UIFont systemFontOfSize:12.0f];
button.titleLabel.textColor=[UIColor blackColor];
button.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin;
// [button setTag:(indexPath.section)];
button.tag=22;
[cell1.contentView addSubview:button];
}
cell1.backgroundColor=[UIColor clearColor];
CGSize constraint1 = CGSizeMake(160+100-140, 20000.0f);
CGSize size1 = [[ArrayForActor objectAtIndex:indexPath.section] sizeWithFont:[UIFont systemFontOfSize:16.0f] constrainedToSize:constraint1 lineBreakMode:UILineBreakModeWordWrap];
CGSize constraint = CGSizeMake(160+100, 20000.0f);
CGSize size = [cellValue sizeWithFont:[UIFont systemFontOfSize:17.0f] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
if (temp.type==2) {
if ([temp.mobileNo isEqualToString:mahesh.mobileno])
{
if (size.width>(size1.width+180)) {
cell1.ViewContainer.frame=CGRectMake(0,0,size.width+4 ,size1.height+50);
}else{
cell1.ViewContainer.frame=CGRectMake(0,0,size1.width+4+180 ,size1.height+50);
}
cell1.ViewContainer.backgroundColor=[UIColor yellowColor];
cell1.dateText.frame=CGRectMake(cell1.ViewContainer.frame.size.width-140,cell1.ViewContainer.frame.origin.y ,135 ,20);
}else{
if (size.width>(size1.width+180)) {
cell1.ViewContainer.frame=CGRectMake(self.view.frame.size.width-size.width+4,0,size.width+4 ,size1.height+50);
}else{
cell1.ViewContainer.frame=CGRectMake(self.view.frame.size.width-size1.width-180+4,0,size1.width+4+180 ,size1.height+50);
}
cell1.dateText.frame=CGRectMake(self.chatTable.frame.size.width-140,cell1.ViewContainer.frame.origin.y ,135 ,20);
cell1.ViewContainer.backgroundColor=[UIColor greenColor];
}
}else{
if ([temp.mobileNo isEqualToString:mahesh.mobileno])
{
if (size.width>(size1.width+180)) {
cell1.ViewContainer.frame=CGRectMake(0,0,size.width+4 ,size.height+4+size1.height+4);
}else{
cell1.ViewContainer.frame=CGRectMake(0,0,size1.width+4+180 ,size.height+4+size1.height+4);
}
cell1.ViewContainer.backgroundColor=[UIColor yellowColor];
cell1.dateText.frame=CGRectMake(cell1.ViewContainer.frame.size.width-140,cell1.ViewContainer.frame.origin.y ,135 ,20);
}else{
if (size.width>(size1.width+180)) {
cell1.ViewContainer.frame=CGRectMake(self.view.frame.size.width-size.width-4,0,size.width+4 ,size.height+4+size1.height+4);
}else{
cell1.ViewContainer.frame=CGRectMake(self.view.frame.size.width-size1.width-180-4,0,size1.width+4+180 ,size.height+4+size1.height+4);
}
cell1.dateText.frame=CGRectMake(self.chatTable.frame.size.width-140,cell1.ViewContainer.frame.origin.y ,135 ,20);
cell1.ViewContainer.backgroundColor=[UIColor greenColor];
}
}
cell1.actorLabel.frame=CGRectMake(cell1.ViewContainer.frame.origin.x+2,cell1.ViewContainer.frame.origin.y,size1.width+4,size1.height+4);
cell1.actorLabel.text=[ArrayForActor objectAtIndex:indexPath.section];
cell1.chatText.frame=CGRectMake(cell1.ViewContainer.frame.origin.x,cell1.actorLabel.frame.size.height-12, cell1.ViewContainer.frame.size.width,size.height+4+4);
UIButton *thisInviteButton = (UIButton*)[cell1.contentView viewWithTag:22];
thisInviteButton.hidden=YES;
if (temp.type==2) {
thisInviteButton.hidden=NO;
thisInviteButton.frame=CGRectMake((cell1.ViewContainer.frame.size.width/2)-50,size1.height, 100,40);
}else{
}
cell1.dateText.textAlignment=UITextAlignmentRight;
cell1.chatText.textAlignment = UITextAlignmentLeft;
cell1.chatText.text= cellValue;
cell1.selectionStyle=NO;
NSTimeInterval interval=[temp.createdDate longLongValue];
NSDate *currentTime=[NSDate dateWithTimeIntervalSince1970:interval/1000];
NSLocale *gbLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_GB"];
NSNumber *myDateInString=[NSNumber numberWithLongLong:[[NSDate date] timeIntervalSince1970]*1000];
NSTimeInterval inte=[myDateInString longLongValue];
NSDate *todayTime=[NSDate dateWithTimeIntervalSince1970:inte/1000];
NSString * todayString = [[todayTime description] substringToIndex:10];
NSString *messageDate=[[currentTime description] substringToIndex:10];
if ([todayString isEqualToString:messageDate]) {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
NSString *formatString = [NSDateFormatter dateFormatFromTemplate:@"hh.mm" options:0
locale:gbLocale];
[dateFormatter setDateFormat:formatString];
[dateFormatter setLocale:gbLocale];
cell1.dateText.text=[NSString stringWithFormat:@"%@",[dateFormatter stringFromDate:currentTime]];
}else {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
NSString *formatString = [NSDateFormatter dateFormatFromTemplate:@"dMMMyy,hh.mm" options:0
locale:gbLocale];
[dateFormatter setDateFormat:formatString];
[dateFormatter setLocale:gbLocale];
cell1.dateText.text=[NSString stringWithFormat:@"%@",[dateFormatter stringFromDate:currentTime]];
}
return cell1;