0

tablview 行に成功テキストを表示した後、ラベルと余分なテキストを行に入れることができませんでした。通常のフォントのテキストと細いフォントの追加テキストとして。このコードを実行すると、データベースに「creation_date」が含まれる 18 行がデバイスに表示されます。しかし、各行の「作成日」と「名前」を表示したい。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;

}

4

1 に答える 1

2

カスタム UITableViewCell を使用することをお勧めします。

LaFiltersTableCell.h

@interface LAFiltersTableCell : UITableViewCell {
}
@property (strong, nonatomic) IBOutlet UILabel *filterNameLabel;
@property (strong, nonatomic) IBOutlet UILabel *selectedOptionsLabel;

LaFiltersTableCell.m

 + (LAFiltersTableCell *)getNewLAFiltersTableCell {
     NSArray *xib = [[NSBundle mainBundle] loadNibNamed:@"LAFiltersTableCell" owner:nil options:nil];
     for (NSObject *obj in xib) {
         if ([obj isKindOfClass:[LAFiltersTableCell class]]) {
             return (LAFiltersTableCell *)obj;
         }
     }
     return nil;

}

カスタム セルの nib ファイルを作成し、次の点に注意してください。nib ビューのクラスは LAFiltersTableCell である必要があり、設定する IBOutlets をリンクし、テーブルビューのデータ ソースで使用するセル識別子を設定します。

テーブルビューのデータソース:

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
     LAFiltersTableCell *filterCell = [tableView dequeueReusableCellWithIdentifier:@"LAFiltersTableCell"];
     if (filterCell == nil) {
         filterCell = [LAFiltersTableCell getNewLAFiltersTableCell];
     }
     filterCell.filterNameLabel = @"Test";
     filterCell.selectedOptionsLabel = @"Some other Test";
    return filterCell
 }
于 2013-11-05T17:26:29.283 に答える