- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我创建了一个自定义 UITableViewCell,其中包含 2 个标签。一个应该有固定的宽度,而另一个应该向右扩展,只要有空间即可。
我正在创建这样的 UILabels:
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
codeLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 60, 20)];
[self.contentView addSubview:codeLabel];
[codeLabel release];
nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(76, 4, self.frame.size.width - 100, 34)];
[self.contentView addSubview:nameLabel];
[nameLabel release];
}
return self;
}
问题是,此时,self.frame.size.width
始终返回 320.0,因此 UILabels 的大小不正确。我该如何克服这个问题?
最佳答案
将第二个标签的autoresizingMask
设置为UIViewAutoresizingFlexibleWidth
。
如果您的需求比 autoresizingMask
所能表示的更复杂,您需要实现自己的 layoutSubviews
。
关于ios - initWithStyle 上的 UITableViewCell 宽度 :reuseIdentifier:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8955301/
我想从已弃用的 initWithFrame:reuseIdentifier: 更新我的 TableView。 我的表格 View 使用自定义单元格。 到处都说要使用 initWithStyle:,并且
我正在一个项目中尝试使用这个框架 VPPDropdown 但我希望它与 storyboard 一起使用. 那我做了什么?我拖了一个UITableviewController在屏幕上。然后在我的代码中我
我有 SIGSEGV 的崩溃报告。我认为这真的不明显,因为有: 无后台 UI 操作。 没有外部 CALayer 操作。 UITableViewCell 以编程方式初始化,不使用 xib 或 Story
我在尝试在一个单元格中显示信息时遇到问题,一个在左边,一个在右边。我知道将 initWithStyle 与 UITableViewCellStyleSubtitle 一起使用。我用这个,但它似乎不起作
据我了解,似乎有三种布局自定义表格 View 单元格的方法: 在界面生成器中。 在 layoutSubviews . 在 initWithStyle:reuseIdentifier: . 第二种方法和
我创建了一个自定义 UITableViewCell,其中包含 2 个标签。一个应该有固定的宽度,而另一个应该向右扩展,只要有空间即可。 我正在创建这样的 UILabels: - (id)initWit
我最近做了一个表格单元格子类的编程分配/初始化,并且通过一些 NSLog,我能够了解到几乎所有的初始化程序都被调用了,即使我所做的只是分配/初始化,如果我记得的话正确。 初始化 初始化样式 这是什么逻
类引用说: 如果您使用标准的 init 方法来初始化 UITableViewController 对象,则会创建一个普通样式的 TableView 。 我不明白,这种行为是从哪里来的——我想在一些代码
我创建了自定义单元格,其中有 n 个 ImageView 。根据每行 ImageView 的数量,我放置了 ImageView 的大小。为此,我需要 initWithStyle: UITableVie
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPa
我的if语句中不断收到Expected Identifier - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtI
我收到错误“@LWWFirstController 的可见接口(interface)声明了选择器 initWithStyle”。我已经编写了类似的代码来设置我的导航 Controller 并且它工作正
据我所知,这在 Apple Api 中是正确的,当使用 initWithStyle 方法初始化 UITableViewController 时,它应该返回对 self.tableView 中 UITa
我是一名优秀的程序员,十分优秀!