Dan*_*552 6 objective-c uitableview ios
我觉得这里发生了一些奇怪的事情.我有一个原型单元格,其中有一些标签作为子视图,并且viewWithTag尝试找到它们来设置文本.我在同一个项目中已经完成了3次,所以我迷失了可能是错的.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Result Cell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
UILabel *racerNameLabel = (UILabel*) [cell viewWithTag:5002153];
//more labels ...
return cell;
}
Run Code Online (Sandbox Code Playgroud)
如果我输入断点,racerNameLabel为nil且单元格没有子视图:
(lldb) po [[cell contentView] subviews]
(id) $5 = 0x08161da0 <__NSArrayI 0x8161da0>(
)
Run Code Online (Sandbox Code Playgroud)
这是故事板本身的一个噱头,显示标签子视图应该绝对存在.它还显示了单元标识符是否正确.
<tableViewCell contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="Result Cell" rowHeight="80" id="hGh-MB-iBH">
<rect key="frame" x="0.0" y="22" width="382" height="80"/>
<autoresizingMask key="autoresizingMask"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
<rect key="frame" x="0.0" y="0.0" width="382" height="79"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" tag="5002153" contentMode="left" text="Racer Name" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Sf6-ol-OLA">
<constraints>
<constraint firstAttribute="width" constant="166" id="iI1-0U-gN8"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="highlightedColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</label>
Run Code Online (Sandbox Code Playgroud)
(注意我将标签设置为愚蠢的数字,试图使其正常工作)
Cyu*_*upa 20
如果要使用在Interface Builder中的Inspector中输入的限定符注册自定义UITableViewCell单元格,则可能是问题所在.我有同样的问题,当我删除在viewDidLoad中注册自定义类的行时,它工作.
| 归档时间: |
|
| 查看次数: |
1573 次 |
| 最近记录: |