0

I develop a custom tableviewcell for use across my projcect, named UpdatesTableViewCell class. what I've got up until now has been shown in the snapshots at the bottom of this question.

Only problem I've been unfortunately experiencing is all about that the app layout only work in portrait orientation, but not in landscape mode.

That's to say, when my iphone get rotated to landscape, the above mentioned custom cell doesn't seem to fill up all the space of the containing table view, leaving some gap after it. That would not be of pleasant user experience.

please note that I also set autosizing to tell the tableviewcell to expand both left and right, filling up the container's space. (See 1st snapshot picture)

any advice to get it right in landscape orientation would be very much appreciated

..

UpdatesTableViewCell.xib

enter image description here

UpdatesTableViewCell.h

#import <UIKit/UIKit.h>

@interface UpdatesTableViewCell : UITableViewCell

@end

UpdatesTableViewCell.m

#import "UpdatesTableViewCell.h"

@implementation UpdatesTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end

and the final piece here is a snippet of code in ResultViewController.m (The parent UITableViewController where the UpdatesTableViewCell get used)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UpdatesTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {

        NSArray* views = [[NSBundle mainBundle] loadNibNamed:@"UpdatesTableViewCell" owner:nil options:nil];

        for (UIView *view in views) {
            if([view isKindOfClass:[UITableViewCell class]])
            {
                cell = (UpdatesTableViewCell*)view;
            }
        }
    }

    return cell;
}

Here is the unexpected result as mentioned:

enter image description here

4

1 回答 1

2

请注意,我还设置了 autosizing 来告诉 tableviewcell 向左和向右扩展,填满容器的空间。(见第一张快照图片)

您需要标记水平箭头以调整宽度。

你现在拥有的是:

UIViewAutoresizingFlexibleLeftMarginUIViewAutoresizingFlexibleRightMargin
视图通过在左/右边缘的方向上扩展或收缩来调整大小。

你需要的是:

UIViewAutoresizingFlexibleWidth
视图通过扩大或缩小其宽度来调整大小。

于 2013-04-16T09:13:24.397 回答