У меня странная проблема с новым набором текста iOS 7.iOS 7 Text Kit пропускает текст в макете
Я создал очень простую программу для демонстрации. Он читает содержимое файла, который содержит числа 1 - 300 в одном столбце. Он отображает текст на одной «странице» за раз после нажатия на UITextView. (У меня есть один вид, и я просто продолжаю удалять и заменять UITextView новым, созданным с помощью NSTextContainer).
На первой странице отображаются номера 1 - 136. Вторая страница должна начинаться с 137, но это не так. Вторая страница начинается с 155 и заканчивается на 262. Текстовый набор пропустил 18 текстовых строк. Затем третья страница начинается с 281 (пропуская 19 текстовых строк) и отображает остальную часть номера до 300.
Может кто-нибудь посмотреть на код и рассказать мне, что мне не хватает?
#import "ViewController.h"
@interface ViewController()
@property (nonatomic, strong) UITextView *textView;
@property (nonatomic, strong) NSLayoutManager *layoutManager;
@property (nonatomic, strong) UITapGestureRecognizer *tapGestureRecognizer;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// read file into NSTextStorage
NSURL *url = [[NSBundle mainBundle] URLForResource:@"Workbook1" withExtension:@"html"];
NSTextStorage *storage = [[NSTextStorage alloc] initWithFileURL:url
options:nil
documentAttributes:nil
error:nil];
// add new NSLayoutManager to NSTextStorage
_layoutManager = [[NSLayoutManager alloc] init];
[storage addLayoutManager:_layoutManager];
// load first page
[self handleSingleTapForward];
}
-(void)handleSingleTapForward{
// crate a new NSTextContainer and add it to the NSLayoutManager
CGSize sizeX = CGSizeMake(200.0, 300.0);
NSTextContainer *textContainer = [[NSTextContainer alloc] initWithSize:sizeX ];
[_layoutManager addTextContainer:textContainer];
// remove the previous UITextView
if (_textView) {
[_textView removeFromSuperview];
}
// create new text view using the NSTextContainer for its content
CGRect rectX = CGRectMake(100, 100, 200, 300);
_textView = [[UITextView alloc] initWithFrame:rectX textContainer:textContainer];
_textView.textContainerInset = UIEdgeInsetsMake(50, 30, 50, 30);
_textView.scrollEnabled = NO;
// Set up the gesture recognizer to call handleSingleTapForward: on a single tap
_tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTapForward)];
[_tapGestureRecognizer setNumberOfTapsRequired:1];
[_textView addGestureRecognizer:_tapGestureRecognizer];
// Add the new UITextView to the main view.
[self.view addSubview:_textView];
}
@end
Файл вход очень прост и выглядит следующим образом (обрезается, чтобы сохранить пространство):
<html><body>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
...
300
</body></html>
Вы должны подождать, чтобы проверить, не видит ли кто-нибудь проблему с вашим кодом, и если они не видят проблемы, тогда вы должны взять примерный проект, который показывает эту проблему, и вы должны зарегистрировать его с помощью Apple по адресу: https://bugreport.apple.com –