customcell autoresizingMask
プロパティのコンテンツ ビューを設定しましたが、正常UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin |UIViewAutoresizingFlexibleRightMargin;
に動作しますが、デバイス コンテンツ ビューの画面を回転すると幅が変更されましたが、テーブルをスクロールするとコンテンビューの幅が変更されます (デリゲート メソッド tableView: で計算されたサイズになりますtableView cellForRowAtIndexPath: indexPath
)。上記の問題と2番目の質問は、スクロールした後、横向きから縦向きに戻すと、コンテンツビューの幅が狭くなります。
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;