iPhone SDKでアプリを開発していますが、デバイスが横向きモードのときにテーブルビューセルのコンテンツのサイズを変更したいと思います。
テーブルビューセルには、同期画像と2つのラベルがあります。ポートレートモードでは見栄えがよくなりますが、デバイスをランドスケープにすると、テーブルビューのコンテンツのサイズが変更されません。
これを手伝ってくれる人はいますか?
このコードはのためのものでionterfaceOrientation
あり、これが横向きの場合はreloadData
、テーブルビューを呼び出します。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (interfaceOrientation == UIDeviceOrientationLandscapeLeft || interfaceOrientation == UIDeviceOrientationLandscapeRight)
{
NSLog(@"LandsCape Mode");
[mytabla reloadData];
}else{
NSLog(@"Portrait Mode");
}
return YES;
// for supported orientations
//return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
これまではすべて問題ありませんが、テーブルビューでコンテンツのサイズが変更されません。
これは私のテーブルビューを初期化するコードですcellForRowAtIndexPath:(NSIndexPath *)indexPath
AsyncImageView *asyncImageView = nil;
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
CGRect frame;
frame.origin.x = 5;
frame.origin.y = 10;
frame.size.width = 70;
frame.size.height = 60;
asyncImageView = [[[AsyncImageView alloc] initWithFrame:frame] autorelease];
asyncImageView.tag = ASYNC_IMAGE_TAG;
cell.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
frame.origin.x = 52 + 10;
frame.size.width = 200;
NSString *urlSeccion = aBook.Titulo;
urlSeccion = [urlSeccion stringByReplacingOccurrencesOfString:@"\n" withString:@""];
NSString *SeccionSummary = aBook.Summary;
SeccionSummary = [SeccionSummary stringByReplacingOccurrencesOfString:@"\n" withString:@""];
[cell.contentView addSubview:asyncImageView];
upLabelText = [[UILabel alloc] initWithFrame:CGRectMake(90, cell.frame.origin.y, cell.frame.origin.size, 50)];
upLabelText.textColor = [UIColor blackColor];
upLabelText.text = urlSeccion;
[upLabelText setNumberOfLines:2];
[upLabelText setLineBreakMode:UILineBreakModeWordWrap];
upLabelText.font = [UIFont systemFontOfSize:13.0];
downLabelText = [[UILabel alloc] initWithFrame:CGRectMake(90, 45, cell.frame.origin.size, 50)];
downLabelText.textColor = [UIColor blackColor];
downLabelText.text = SeccionSummary;
[downLabelText setNumberOfLines:5];
[downLabelText setLineBreakMode:UILineBreakModeWordWrap];
downLabelText.font = [UIFont systemFontOfSize:8.0];
[cell.contentView addSubview:downLabelText];
[cell.contentView addSubview:upLabelText];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
asyncImageView = (AsyncImageView *) [cell.contentView viewWithTag:ASYNC_IMAGE_TAG];
NSString *urlSeccionImagen = aBook.ThumbnailURL;
urlSeccionImagen = [urlSeccionImagen stringByReplacingOccurrencesOfString:@" " withString:@""];
urlSeccionImagen = [urlSeccionImagen stringByReplacingOccurrencesOfString:@"\n" withString:@""];
urlSeccionImagen = [urlSeccionImagen stringByReplacingOccurrencesOfString:@" " withString:@""];
NSString *urlString = [NSString stringWithFormat:urlSeccionImagen,indexPath.row + 1];
NSURL *url = [NSURL URLWithString:urlString];
[asyncImageView loadImageFromURL:url];
return cell;
}
ラベルはサイズ変更に反応せず、テーブルビューに揺れがあります。私が考えているのは、テーブルビューをリセットすることですが、その方法がわかりません。