0

UITableView 内に TTStyledTextLabel を設定するにはどうすればよいですか。各 TTStyledTextLabel には、解析された HTML が含まれています。

私が持っているものは、おそらく完全に間違っていることに気づきました。

TTStyledTextLabel* label = [[TTStyledTextLabel alloc] autorelease];
cell.textLabel.text = [TTStyledText textFromXHTML:tempString lineBreaks:YES URLs:YES];

起動時にアプリがクラッシュします。テキストではないもので .text プロパティを設定しているためだと思います。ただし、他に何を設定すればよいかわかりません。

4

1 に答える 1

0

次のコードは、あなたが望むことを行います。残念ながら、高さを自動的に設定する方法がわかりません。メモリが問題にならない場合は、TTStyledTextLabels の別の配列を保持し、それらの高さを参照できます。

あなたのloadViewで:

CGRect cgRct2 = CGRectMake(0, 35, 320, 375); //define size and position of view 
    tblView = [[UITableView alloc] initWithFrame:cgRct2 style:UITableViewStylePlain];
    tblView.dataSource = [self constructDataSource];
    tblView.delegate = self;
    //[tblView reloadData];
    [myView addSubview:tblView];

あなたのクラスで:

-(TTListDataSource *)constructDataSource {
    NSLog(@"constructDataSource");
    NSMutableArray * namesArray = [[NSMutableArray alloc] init];

    //ADD ITEMS
    [namesArray addObject:[TTStyledText textFromXHTML:[NSString stringWithString:@"some XHTML"]]];




    TTListDataSource * dataSource = [[TTListDataSource alloc] init];
    for (int i = 0; i < [namesArray count]; i++) {
        TTStyledText * text = [namesArray objectAtIndex:i];

        [dataSource.items addObject:[TTTableStyledTextItem itemWithText:text]];
    }

    [namesArray release];
    return dataSource;
}
于 2010-11-19T22:57:44.687 に答える