简体   繁体   English

如何在分组的Tableview单元中使图像的宽度等于屏幕的宽度?

[英]How can I make an image in a grouped tableview cell the width of the screen?

I have large images displayed in a grouped tableview. 我在分组的表格视图中显示了大图像。 I would like the images to fill the entire width of the screen. 我希望图像填充屏幕的整个宽度。 I have been able to make this work using a tableViewCell interface builder, but in an attempt to improve performance I am now trying to do this programmatically. 我已经能够使用tableViewCell接口构建器来完成这项工作,但是为了提高性能,我现在正尝试以编程方式进行此操作。

However, I have not been able to get the image to be flush against the left side of the screen. 但是,我无法使图像与屏幕左侧齐平。 It seems to be using the default position of the cells in the grouped tableview. 似乎在使用分组表格视图中单元格的默认位置。

I was able to make it work using a plain tableview, but then the section headers anchor on the top of the screen and I need them to scroll. 我能够使用普通的tableview使其工作,但是节标题停在屏幕顶部,因此我需要它们滚动。

Any ideas how to do this programmatically? 任何想法如何以编程方式执行此操作? Here's my original code below. 这是下面的原始代码。 Thanks! 谢谢!

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *MyTableViewCellIdentifier = @"Cell";

MyTableViewCell *cell = (MyTableViewCell *) 
            [tableView dequeueReusableCellWithIdentifier: MyTableViewCellIdentifier];

    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MyTableViewCell" owner:self options:nil];
    for(id currentObject in nib)

        {
            cell = (DetailTableViewCell *)currentObject;
        }

MyAppAppDelegate *appDelegate = (MyTableViewCell *)[[UIApplication sharedApplication] delegate];
NSString *Path = [[NSBundle mainBundle] bundlePath];
NSString *MainImagePath = [Path stringByAppendingPathComponent:
        ([[appDelegate.myDictionaryOfImages objectAtIndex:indexPath.section] objectForKey:@"LargeImage"])];

cell.myLargeImage.image = [UIImage imageWithContentsOfFile:MainImagePath];

return cell;
}

I finally got it working. 我终于让它工作了。 Here is my final code. 这是我的最终代码。

#define PHOTO_TAG 1

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

UIImageView *photo;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
UIImage *theImage = [UIImage imageNamed:[[appDelegate.sectionsDelegateDict objectAtIndex:indexPath.section] objectForKey:@"MainImage"]];

imageHeight = CGImageGetHeight(theImage.CGImage);
imageWidth = CGImageGetWidth(theImage.CGImage);

if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    photo = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, imageWidth, imageHeight)] autorelease];
    photo.tag = PHOTO_TAG;
    [cell addSubview:photo];
} else {
    photo = (UIImageView *) [cell viewWithTag:PHOTO_TAG];
    [photo setFrame:CGRectMake(0, 0, imageWidth, imageHeight)];
}

photo.image = theImage;
return cell;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何控制图像在分组的表格单元格中的位置? - How do I control the position of an image in a grouped tableview cell? 如何以编程方式将TableView设置为分组 - How can I programmatically set a TableView to be grouped 如何为tableview的每个单元格设置不同的图像 - How can i set a different image for each cell of my tableview 如何使用分组单元格调整表格视图中单元格的大小 - How do I resize a cell in a tableview with grouped cells 如何设置UITableView的背景(tableview样式为“Grouped”)才能使用图像? - How can I set the background of UITableView (the tableview style is “Grouped”) to use an image? 我如何自定义iPhone的uitableview(grouped)一部分的单元格宽度? - how can i customise the width of the cell which are the part of uitableview(grouped) in iphone? 如何制作宽度不全屏的UINavigationController? - How can I make a UINavigationController that is not full screen in width? 如何立即将单元格添加到表视图 - How can I instantaneously add a cell to a tableview 如何访问分组表格视图的一个特定部分? - How can I access one particular section of a grouped tableview? 如何检测表格视图在屏幕上任何地方的触摸,而不仅仅是单元格? - How do I detect touches anywhere on the screen of a tableview, not just the cell?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM