【发布时间】:2013-05-31 11:05:39
【问题描述】:
我是新人,我添加了这段代码来自定义表格视图,其中包含图像和按钮
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ImageOnRightCell";
UILabel *mainLabel, *secondLabel;
UIImageView *photo;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(100, 0.0, 100, 20)];
[button addTarget:self action:@selector(buttonPressedAction:) forControlEvents:UIControlEventTouchUpInside];
[button setTag:1];
[cell.contentView addSubview:button];
photo = [[UIImageView alloc] initWithFrame:CGRectMake(50.0, 0.0, 80.0, 45.0)];
photo.tag = PHOTO_TAG;
photo.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:photo];
}
UIImage *theImage = [UIImage imageNamed:@"man.jpg"];
photo.image = theImage;
return cell;
}
图像部分出现在表格的行中,但不是按钮。 请问这是什么问题
【问题讨论】:
-
请修正代码格式。
-
尝试给按钮标题或背景颜色。实际上自定义单元格是不错的选择
-
问题出在按钮的框架上。部分按钮位于 imageView 后面。将按钮的 x 坐标更改为 150 并查看
标签: ios uitableview customization