我有一个静态单元存储用户可以输入字段的信息形式。其中一个静态单元用于附件。我想在用户从UIImagePickerController中选择一个图像时将一些UIView附加到这个单元格中。我已经处理了UIImagePickerController部分。我有找到reuseIdentifier细胞:如何在UITableViewController的静态单元中添加UIView?
UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"AttachmentCell"];
我试图追加在我的手机的看法:
CGRect attachmentFrame = CGRectMake(0, 0, 50, 50);
UIView * attachmentRow = [[UIView alloc]initWithFrame: attachmentFrame];
CGFloat ratio = 50/image.size.width;
CGRect imageFrame = CGRectMake(10, 0, image.size.width * ratio, 50);
CGRect imageNameLabelFrame = CGRectMake(10 + imageFrame.size.width + 10, 22, 300, 6);
UIImageView *imageView = [[UIImageView alloc]initWithFrame: imageFrame];
imageView.image = image;
UILabel *imageNameLabel = [[UILabel alloc]initWithFrame:imageNameLabelFrame];
imageNameLabel.text = [NSString stringWithFormat:@"Attachment %d", attachmentCounter++];
[attachmentRow addSubview: imageView];
[attachmentRow addSubview: imageNameLabel];
attachmentRow.backgroundColor = [UIColor lightGrayColor];
[cell.contentView addSubview: attachmentRow];
NSLog(@"Row appended");
注意,上面的代码只是为了尝试在静态小区追加一个单一视图但似乎失败了。添加视图后,静态单元格中没有显示任何内容。我记录了我的附件数据可以成功引入此页面。
你的行高是多少? –
我在故事板中将其设置为300 –
您在哪里创建单元格? – JomanJi