【发布时间】:2013-11-05 17:14:40
【问题描述】:
在我的 tablview 行中显示成功文本后,我没有设法在行中放置标签和一些额外的文本。作为普通字体的文本和更小字体的额外文本。 当我执行此代码时,我的设备会在我的数据库中显示 18 行,其中包含“creation_date”的内容。但我想显示每一行的“creation_date”和“名称”。如果我复制并粘贴 cell.textLabel 行并将“creation_date”更改为“name”,我会得到一个 SIGABRT:8 如果有人可以帮助我吗?这是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @"Cell";
NSString *LBLS = @"go";
NSString *LBLR =@"smogogo";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
CGRect frame = CGRectMake(0, 0, 160, 50);
UILabel *lbl1 = [[UILabel alloc] initWithFrame:frame];
lbl1.textAlignment = UITextAlignmentRight;
[lbl1 setFont:[UIFont fontWithName:@"Helvetica" size:12.0]];
[lbl1 setTextColor:[UIColor grayColor]];
int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
LBLS = [[stories objectAtIndex:storyIndex] objectForKey: @"module"];
if ([LBLS isEqualToString:dataType]){
lbl1.text = [[stories objectAtIndex: storyIndex] objectForKey: @"creation_date"];
LBLS = [[stories objectAtIndex:storyIndex] objectForKey: @"module"];
if ([LBLS isEqualToString:dataType])
[cell.contentView addSubview:lbl1];
[lbl1 release];}
CGRect frame2 = CGRectMake(0, 0, 250, 50);
UILabel *lbl2 = [[UILabel alloc] initWithFrame:frame2];
lbl2.textAlignment = UITextAlignmentRight;
[lbl2 setFont:[UIFont fontWithName:@"Helvetica" size:12.0]];
[lbl2 setTextColor:[UIColor blackColor]];
lbl2.text = [[stories objectAtIndex: storyIndex] objectForKey: @"name"];
if ([LBLS isEqualToString:dataType]){
[cell.contentView addSubview:lbl2];
[lbl2 release];}
return cell;
}
【问题讨论】:
-
自 iOS 3.0 起,
UITableViewCell initWithFrame:reuseIdentifier:方法已被弃用。使用正确的方法设置单元格的样式。 -
好的,我会想办法重新编辑,但我担心的是 cell.textLabel 行。
-
您有什么顾虑?你的问题很不清楚。
-
谢谢你不放弃^^。当我执行此代码时,我的设备会显示 18 行以及我的数据库中的 creation_date。但我想显示 creation_date 和每一行的名称。如果我复制并粘贴 cell.textLabel 行并使用名称更改 creation_date,我会得到一个 SIGABRT :8。
-
用给你带来问题的代码更新你的问题。
标签: ios objective-c text