3

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;
}

ラベルはサイズ変更に反応せず、テーブルビューに揺れがあります。私が考えているのは、テーブルビューをリセットすることですが、その方法がわかりません。

4

4 に答える 4

3

この共有をありがとう。これは、UITableViewCell をセットアップするメソッドを持つ素晴らしいアイデアです。しかし、次のコード行だけで uitableviewcell のコンテンツをサイズ変更できることがわかりました。

tituloLabelText.autoresizingMask = ( UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
tituloLabelText.text = @"A Large text resides here";
[tituloLabelText setNumberOfLines:2];
[tituloLabelText setLineBreakMode:UILineBreakModeWordWrap];

autoresizingMask の行だけで、コントロールが幅と高さを変更できるようになります。

于 2009-09-23T20:52:32.213 に答える
1

私はカスタムUITableViewCellで同様の問題を抱えており、最終的に画像を非同期にダウンロードし(あなたのように)、AppleのUITableViewCellが提供するimageViewに設定しました(サブビューとして追加されたカスタムimageViewではありません)。

サイズを変更する必要があるラベル (テキストが縦長の 1 行よりも長い) の場合、テキストをデフォルトの textLabel に設定すると、自動的にサイズが変更されました。日付を含む2番目のラベルもありました(テキストは短く、サイズ変更は必要ありませんでした)、セルのコンテンツビューにサブビューとして追加しました。

最初に、上記のコードで行ったことを行いました.. uilabels をセットアップし、それらをサブビューとして追加しましたが、向きの変更アラートが tableView からそれらに渡されなかったことを発見したため、横向きでは期待どおりに見えませんでした..

ここで見つけることができるUITableViewCellの詳細UITableViewCell

私のカスタムUITableViewセルには、セルのデータをセットアップするメソッドがありました...次のようなものです:

    - (void) setData:(Feed *) dict
{
    self.autoresizesSubviews = YES;
    self.imageView.image = [UIImage newImageFromResource:@"noFeedImg.png"];
    self.textLabel.highlightedTextColor = [UIColor whiteColor];
    [[self textLabel] setOpaque:NO];
    [[self textLabel] setBackgroundColor:[UIColor clearColor]];
    [[self textLabel] setText:[dict feedTitle]];
    [[self textLabel] setTextColor:[UIColor blackColor]];
    [[self textLabel] setNumberOfLines:3];
    [[self textLabel] setFont:[UIFont boldSystemFontOfSize:12]];

    [self addSubview:dateLabel];
    dateLabel.text = [dict publishDate];
    dateLabel.frame = CGRectMake(self.contentView.bounds.origin.x + 125, 100, 175, 14);
    self.URL = [dict feedURL];

    [imageLoader loadImageFromURL:[NSURL URLWithString:@"http://www.google.com"] withCallbackTarget:self withCallbackSelector:@selector(setupImage:)];
}

セルを作成した後の cellForRowAtIndexPath で:

FeedTableViewCell *cell = [[[FeedTableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];

その後、セルに表示される情報を設定します。

[cell setData:[feedsList objectAtIndex:feedIndex]];

これがあなたを助けることを願っています。

于 2009-09-17T09:22:21.107 に答える
0

カスタム セルが IB autoresizingMask = UIViewAutoresizingFlexibleWidth に接続されている場合、何らかの理由で機能しません。

ビューが読み込まれるときにカスタム セルのサイズを変更し、ビューの回転を無効にします。このコードは iPhone で動作します。iPadには+256が必要だと思いますが、テストしたことはありません

- (void)viewDidLoad
  {
    [super viewDidLoad];

    if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight) {
    CGRect newFrame = customCell.frame;
    newFrame.size.width = newFrame.size.width+160;
    customCell.frame = newFrame;
  }
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return NO;
}
于 2012-08-13T20:08:35.557 に答える
0

shouldAutorotateToInterfaceOrientationメソッドで次の単純な行を使用できます。

self.view.autoresizesSubviews = YES;
于 2012-08-03T15:07:50.317 に答える