iOS - 自定义表格单元格不是 UITableView 的全宽

标签 ios objective-c uitableview autolayout

我可能做错了。所以我创建了一个 UITableView,它基本上有一个自动布局尾随空间设置为主视图。我正在为此表创建一个自定义单元格,因此我在原型(prototype)单元格上添加了药物,对其进行了自定义,并为其创建了我的类。这一切都很好。

我似乎无法解决的是自定义单元格没有占据实际表格单元格的整个宽度,因此只会显示白色背景。如果我不使用自定义单元格,则会使用整个宽度表格单元格。

我为单元格内容设置了约束,以便背景图像填充单元格。

我做错了什么?让我知道您需要什么来帮助解决这个问题。

ProfileCustomCell.h

#import <UIKit/UIKit.h>

@interface ProfileCustomCell : UITableViewCell {

}

@property (nonatomic, strong) IBOutlet UILabel *nameLabel;
@property (nonatomic, strong) IBOutlet UIImageView *profileImageView;

@end

ProfileCustomCell.m

#import "ProfileCustomCell.h"

@implementation ProfileCustomCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];

    if (self) {
        self.nameLabel.text = nil;
    }

    return self;

}

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

@end

UITableView

[tableView registerNib:[UINib nibWithNibName:@"ProfileCustomCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"Cell"];

[tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];

ProfileCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

cell.nameLabel.text = [NSString stringWithFormat:@"%@", [child objectForKey:@"first_name"]];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];

enter image description here

最佳答案

你能把代码贴出来吗?

您是否启用了使用自动布局使用尺寸分类,如下所示,首先在表格 View 和表格 View 单元格中执行此操作。然后告诉我您的问题

enter image description here

1)After that select both image and label and do as below

enter image description here

2) Select the image and do below

enter image description here

3) select the label an do the following

enter image description here

你能查看下面的链接吗:

Table cell content(title) moving left after selecting cell

关于iOS - 自定义表格单元格不是 UITableView 的全宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30633739/

相关文章:

ios - 同时使用 TableFooterView 和行操作时 TableView 分隔符的奇怪行为

ios - 使用 xcodebuild 或 Xcode 运行选定的测试类

objective-c - 如何制作 NSString 宏?

objective-c - 未调用 textFieldShouldReturn

iphone - Cocoa Touch 从核心数据更新 UITableView

ios - 无法从父 ViewController 在 UITableViewCell 中设置变量

ios - NSDate - 添加天数不会改变年份值

ios - IBM 工作灯 : iOS Push Notification Length Limit

ios - 基于 UIPinch 缩放图像

ios - Xcode 8.2.1/Swift 3 - 从 Plist 字典数组加载 TableView