调整tableview单元格内容视图的大小

时间:2014-08-12 14:07:11

标签: ios uitableview landscape-portrait

您好我是ios开发的新手。我正在开发应用程序,其中我有一个pageViewController,其中包含子viewController A.在A控制器中我有一个tableview。 我正在处理旋转变化,在横向模式下,我为pageViewController创建了新的CGRect。 现在问题是在landsape模式下我的tableview不适合pageViewController的边界,它的单元格内容不在屏幕上。请给我一个提示。

这是我的控制器代码

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return [_channelsArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *CellIdentifier = @"ChannelsCell";
    MBChannelsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    MBChannel *selectedChannel = [_channelsArray objectAtIndex:indexPath.row];
    cell.channelName.text = selectedChannel.name;
    cell.channelNumber.text = [NSString stringWithFormat:@"%ld %s",indexPath.row + 1, "."];


    if(indexPath.row % 2 == 0){
        cell.contentView.backgroundColor =[UIColor colorWithRed:34.0f/255.0f
                                                          green:91.0f/255.0f blue:172.0f/255.0f alpha:1.0f];
    }else{
        cell.contentView.backgroundColor = [UIColor colorWithRed:41.0f/255.0f
                                                           green:114.0f/255.0f blue:198.0f/255.0f alpha:1.0f];
    }

    UIButton *favourite = cell.buttonFavourite;
    favourite.tag = indexPath.row;

    [favourite addTarget:self
                  action:@selector(makeFavourite:)
        forControlEvents:UIControlEventTouchUpInside];

    UIButton *arrow = cell.buttonArrowRight;
    arrow.tag = indexPath.row;

    [arrow addTarget:self
              action:@selector(navigateToProgram :)
    forControlEvents:UIControlEventTouchUpInside];

    cell.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;


    return cell;
}

1 个答案:

答案 0 :(得分:0)

尝试使用Autolayout。 https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/Introduction/Introduction.html

它允许您根据需要将视图基本上附加到侧面/顶部/底部进行自转。