سؤال

كيف يمكنني ضبط ttstyledtextlabel داخل uitableview. كل ttstyledtextlabel يحتوي على بعض html تحليل.

هيريس ما أدركت أنه ربما يكون خطأً تمامًا.

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

تعطل التطبيق عند الإطلاق. أعتقد أنه لأنني أقوم بتعيين خاصية .Text بشيء غير نص. ومع ذلك ، لا أعرف ماذا يجب تعيينه.

هل كانت مفيدة؟

المحلول

الرمز التالي سيفعل ما تريد. لسوء الحظ ، ومع ذلك ، لا يمكنني معرفة كيفية ضبط الارتفاع تلقائيًا. إذا لم تكن الذاكرة مشكلة ، فيمكنك الاحتفاظ بمجموعة منفصلة من 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;
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top