detailTextLabel不可见(代码如下).你能告诉我为什么吗?
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
NSString *cellValue = [myListArray objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
cell.detailTextLabel.text = @"Hello "; // This is not visible
cell.image = [myListArrayImages objectAtIndex:indexPath.row];
return cell;
}
Run Code Online (Sandbox Code Playgroud) 细节(副标题)文本不会出现.但是,这些数据是可用的,因为当添加println()调用时,它会向控制台输出带有预期数据的Optional("data").在故事板中,UITableViewController设置为正确的类,Table View Cell Style设置为"Subtitle",重用标识符设置为"cell".如何显示字幕信息?
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableViewCell
dispatch_async(dispatch_get_main_queue(), { () -> Void in
cell.textLabel.text = self.myArray[indexPath.row]["title"] as? String
cell.detailTextLabel?.text = self.myArray[indexPath.row]["subtitle"] as? String
println(self.myArray[indexPath.row]["subtitle"] as? String)
// The expected data appear in the console, but not in the iOS simulator's table view cell.
})
return cell
}
Run Code Online (Sandbox Code Playgroud) 这个让我把头发拉出来.我只是想用UITableViewCellStyleSubtitle样式创建一个带有文本和细节的表.但细节并未出现.通常这是因为有人忘记用正确的样式初始化单元格,但这不是在这种情况下发生的事情.我已经尝试了所有四种单元格样式,并且细节没有出现在任何单元格中,尽管当我使用UITableViewCellStyleValue2时文本标签确实向右移动.
我以前多次成功创建了表格.在这种情况下,我能想到的唯一重要区别是我没有使用UITableViewController.相反,我像任何其他视图一样嵌入UITableView,并连接我自己的数据源和委托.
我已经把关键方法归结为:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// Get the UITableViewCell (out of the recycling pool, or de novo)
NSString *reuseID = @"CELL";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseID];
if (not cell) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:reuseID] autorelease];
}
cell.textLabel.text = @"Foo";
cell.detailTextLabel.text = @"Bar";
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.detailTextLabel.frame = CGRectMake(10, 20, 200,22); // required
cell.detailTextLabel.font = [UIFont boldSystemFontOfSize:12]; // also required
//[cell setNeedsLayout]; (makes no difference)
return cell;
}
Run Code Online (Sandbox Code Playgroud)
只有当我包含上面"必需"行的两个(并使用除Default之外的任何单元格样式)时,我才能看到详细文本,即使我这样做,文本标签的位置也完全重叠细节标签的位置.
因此,似乎初始化程序正在创建detailTextLabel UILabel,但将其字体大小设置为零,并将其框架设置为空或屏幕外的内容.(我已经尝试在调试器中检查这些,但它不是很有用 - 字体大小为零,框架为空,表示textLabel和detailTextLabel,但textLabel总是显示正常.)
显然,如果必须,我可以通过手动调整标签大小和字体来解决它.但是,在这种情况下,我必须这样做,这通常只是设置样式,文本和布局是自动的,这让我非常不安.我搜索了谷歌和堆栈溢出,但找不到任何类似问题的引用.有没有人知道这里发生了什么? …
我已经为该单元格设置了一个文本,但是,它显示的文本太长,这会影响要覆盖或不显示的正确详细文本。
我无法更改它,因为我需要下一个视图控制器中的名称。是否可以让它只显示文本,后跟“....”?
例子:
电子电气工程..... 01 >
图例:“Electrical & Electronic Engi....”作为显示在tableview中的文本,“01”作为右侧的detailTextLabel,“>”作为导航。
这应该是它的样子,http://oi58.tinypic.com/2j4vg5k.jpg,但由于某些文本太长,出现如下:http : //oi58.tinypic.com/erc177.jpg
textLabel 和 detailTextLabel 似乎不适合或显示在整行中。我希望正确的 detailTextLabel 仍然存在, textLabel 以“....”结尾
谢谢。
(我是 iOS 编程的新手)
我想写在tableview单元格detailTextLabel的同一行.
例如
Left string right string.
我这样做:
NSMutableAttributedString *descriptionAttribute = [[NSMutableAttributedString alloc] initWithString:descriptionString];
NSMutableAttributedString *dateAttribute = [[NSMutableAttributedString alloc] initWithString:finalDate];
NSMutableAttributedString *shareAttribute = [[NSMutableAttributedString alloc] initWithString:@"Share"];
NSMutableParagraphStyle *dateStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[dateStyle setAlignment:NSTextAlignmentLeft];
NSMutableParagraphStyle *shareStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[shareStyle setAlignment:NSTextAlignmentRight];
[dateAttribute addAttribute:NSForegroundColorAttributeName value:[UIColor grayColor] range:NSMakeRange(0, 13)];
[dateAttribute addAttribute:NSParagraphStyleAttributeName value:dateStyle range:NSMakeRange(0, 13)];
[shareAttribute addAttribute:NSForegroundColorAttributeName value:[UIColor grayColor] range:NSMakeRange(0, 8)];
[shareAttribute addAttribute:NSParagraphStyleAttributeName value:shareStyle range:NSMakeRange(0, 5)];
[descriptionAttribute appendAttributedString:[dateAttribute mutableCopy]];
[descriptionAttribute appendAttributedString:[shareAttribute mutableCopy]];
myTableViewcell.detailTextLabel.attributedText = descriptionAttribute;
Run Code Online (Sandbox Code Playgroud)
如果我\n在日期和共享属性字符串之间添加,结果是好的.
但我希望在同一行上有两个字符串..
一个主意 ?
谢谢
cell!.textLabel?.text = vehicle["vrn"].string
cell?.detailTextLabel?.text = stateString
Run Code Online (Sandbox Code Playgroud)
我想显示stateString为,bold并且还尝试使用textLabel代替,detailedText但是它没有用。
我有一个包含3个部分的设置视图.某些单元格具有不同的样式:默认或值1.当我快速向上或向下滑动,或更改视图并返回时,应该在单元格中的文本(例如,我的单元格中的detailTextLabel与StyleValue1)不再在此处,或者有时在上方或下方的单元格中.这是截图:第一个是正常状态,第二个是来自Version的detailTextLabel进入上面的单元格,第三个是Measurement System detailTextLabel消失了......

这是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
if (indexPath.section == 1 && indexPath.row == 0) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
}
else if (indexPath.section == 2 && indexPath.row == 2) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
}
else {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
}
// Selection style.
cell.selectionStyle = UITableViewCellSelectionStyleGray;
// Vehicles …Run Code Online (Sandbox Code Playgroud)