Post

Replies

Boosts

Views

Activity

Reply to UITextView ios16 beta textView.attributedText = attributedText not working
it has some error add demo file 'TestViewController.m' when convert to ‘TestViewController.m.log’ the code: // // TestViewController.m // TestUITextView // // Created by *** on 2022/6/8. // #import "TestViewController.h" #import "TestTableViewCell.h" #import "TestModel.h" @interface TestViewController ()<UITableViewDataSource,UITableViewDelegate> @property (weak, nonatomic) IBOutlet UITableView *tableView; @property (nonatomic , strong) NSMutableArray *datas; @end @implementation TestViewController - (void)viewDidLoad {   [super viewDidLoad];   // Do any additional setup after loading the view.   [self.tableView registerClass:[TestTableViewCell class] forCellReuseIdentifier:@"TestTableViewCell"];   [self loadData]; } - (void)loadData {   self.datas = [[NSMutableArray alloc] init];   NSString *test = @"testabcdefg";   for (NSInteger i = 0; i < 100; i++) {     NSMutableString *text = [[NSMutableString alloc] init];     [text appendFormat:@"%@ ",@(i)];     NSInteger k = i;     if (k > 10) k = k%10;     for (NSInteger j = 0;j<k;j++) {       [text appendString:test];     }     TestModel *model = [[TestModel alloc] initWithText:text];     [self.datas addObject:model];   }   [self.tableView reloadData]; } - (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {   TestTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TestTableViewCell"];   TestModel *model = self.datas[indexPath.row];   [cell bindModel:model];   return cell; } - (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {   return self.datas.count; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {   TestModel *model = self.datas[indexPath.row];   return model.size.height; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {   [tableView deselectRowAtIndexPath:indexPath animated:NO]; } @end
Jun ’22
Reply to UITextView ios16 beta textView.attributedText = attributedText not working
1.In the ios16beta version, UITextView is used in UITableViewCell. When the cell is reused, and the textView.attributedText assignment is updated, it is not rendered. 2. Our guess is that UITextView has been modified, and the corresponding rendering process is not triggered when assigning. And finally we find that views can be rendered normally when setting 'textView.attributedText=nil' before setting real attribute text, and then setting 'textView.attributedText=realAttributedText' after cleaning. (View UI Hierarch in the view structure, there is a corresponding _UiTextLayoutLayoutFragmentView) 3.Looking at the API, we find that ios16 UITextView has been modified, which means TextKit2 is used for rendering processing by default, and it can 'fall back' to TextKit1 for rendering processing by accessing the layoutManager property. // From iOS 16 onwards, UITextViews are, by default, created with a TextKit 2 NSTextLayoutManager managing text layout (see the .textLayoutManager property). They will dynamically 'fall back' to a TextKit 1 NSLayoutManager if TextKit 1 features are used (notably, if the .layoutManager property is accessed). // This convenience initializer can be used to specify TextKit 1 by default if you know code in your app relies on that. This avoids inefficiencies associated with the needless creation of a NSTextLayoutManager and the subsequent fallback. + (instancetype)textViewUsingTextLayoutManager:(BOOL)usingTextLayoutManager API_AVAILABLE(ios(16.0), tvos(16.0)); // This property accesses the TextKit 2 NSTextLayoutManager. You should generally prefer to use it over the TextKit 1 .layoutManager property if it exists. This property will return nil if TextKit 1 is in use. @property(nonatomic, nullable, readonly) NSTextLayoutManager *textLayoutManager API_AVAILABLE(ios(16.0), tvos(16.0)); // To ensure compatibilty with older code, accessing the .layoutManager of a UITextView - or its .textContainer's .layoutManager - will cause a UITextView that's using TextKit 2 to 'fall back' to TextKit 1, and return a newly created NSLayoutManager. After this happens, .textLayoutManager will return nil - and _any TextKit 2 objects you may have cached will cease functioning_. Be careful about this if you are intending to be using TextKit 2! @property(nonatomic, readonly) NSLayoutManager *layoutManager API_AVAILABLE(ios(7.0)); After setting access to layoutManager, it can be rendered normally. You can reproduce the scene through the following demo file: TestViewController.h TestViewController.m TestTableViewCell.h TestTableViewCell.m TestModel.h TestModel.m The rendering error* occurs when we lay out through 'frame' using UITextView in UITableViewCell, adjust the size of UITextView view and update the corresponding content according to the text content. The reason is that UITextView has been upgraded in ios16beta system, and TextKit 2 is used for rendering processing by default. *(the corresponding _UiTextLayoutLayoutFragmentView is not generated in the view hierarchy). Conclusion: NORMAL when using constraint layout Using the 'frame' layout, it can be reproduced. At present, it is found that there are two ways to restore it (1) Before assignment, clean up self.textView.attributedText = nil (2) When UITextView is created, access the layoutManager property once to trigger the downgrade of rendering processing from TextKit 2 to TextKit 1 This problem has a great impact on the online version, when it will be fixed?
Jun ’22
Reply to UILabel Crash with Attributed Text
please check it! `1 CoreText TFont::UserFallbacksForLanguage(__CFString const*) const (in CoreText) + 184 2 CoreText TFontCascade::InitParams() (in CoreText) + 476 3 CoreText TFontCascade::InitParams() (in CoreText) + 476 4 CoreText TFontCascade::CreateFallback(__CTFont const*, __CFString const*, CTEmojiPolicy) const (in CoreText) + 88 5 CoreText TGlyphEncoder::AppendUnmappedCharRun(unsigned int, TCFRef<CTRun*>&, __CTFont const*, CFRange&, CFRange, TInlineVector<long, 30ul>&, TFontCascade const&, TGlyphEncoder::ClusterMatching, bool) (in CoreText) + 720 6 CoreText TGlyphEncoder::RunUnicodeEncoderRecursively(unsigned int, TCFRef<CTRun*>&&, __CTFont const*, CFRange, TInlineVector<long, 30ul>&, TGlyphEncoder::Fallbacks, TFontCascade const*, __CFString const*, TGlyphEncoder::ClusterMatching, bool) (in CoreText) + 1424 7 CoreText TGlyphEncoder::EncodeChars(CFRange, TAttributes const&, TGlyphEncoder::Fallbacks) (in CoreText) + 1412 8 CoreText TTypesetterAttrString::Initialize(__CFAttributedString const*) (in CoreText) + 448 9 CoreText TTypesetterAttrString::TTypesetterAttrString(__CFAttributedString const*, __CFDictionary const*) (in CoreText) + 160 10 CoreText CTLineCreateWithAttributedString (in CoreText) + 132 11 UIFoundation -[NSCoreTypesetter _stringDrawingCoreTextEngineWithOriginalString:rect:padding:graphicsContext:forceClipping:attributes:stringDrawingOptions:drawingContext:stringDrawingInterface:] (in UIFoundation) + 1740 12 UIFoundation __NSStringDrawingEngine (in UIFoundation) + 1652 13 UIFoundation -[NSString(NSExtendedStringDrawing) boundingRectWithSize:options:attributes:context:] (in UIFoundation) + 156 14 UIKitCore -[UILabel _textRectForBounds:limitedToNumberOfLines:includingShadow:] (in UIKitCore) + 1220 15 UIKitCore -[UILabel _intrinsicSizeWithinSize:] (in UIKitCore) + 484 16 UIKitCore -[UIView(Geometry) sizeToFit] (in UIKitCore) + 136
Nov ’21