Я пытаюсь получить динамический tableviewcell с текстовым просмотром на основе содержимого textview. Он расширяется и выполняет эту работу, но когда я прокручиваю, детектирование отключается, а цвет шрифта текстового поля принимает цвет цвета оттенка. PFB - код и скриншоты.Цвет шрифта UItextView автоматически меняется на цвет оттенков
ViewController.m
#import "ViewController.h"
#import "CustomCellTableViewCell.h"
@interface ViewController()
@property(nonatomic, strong)NSArray *data;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.data = [NSArray arrayWithObjects:@"ONe is here wihth some thins www.google.com",@"Two with soe phone numbers like 002-092-98-283 and link http://google.com,Two with soe phone numbers like 002-092-98-283 and link http://google.com,Two with soe phone numbers like 002-092-98-283 and link http://google.com,Two with soe phone numbers like 002-092-98-283 and link http://google.com",@"ONe is here wihth some thins www.google.com",@"Two with soe phone numbers like 002-092-98-283 and link http://google.com,Two with soe phone numbers like 002-092-98-283 and link http://google.com,Two with soe phone numbers like 002-092-98-283 and link http://google.com,Two with soe phone numbers like 002-092-98-283 and link http://google.com",@"ONe is here wihth some thins www.google.com",@"Two with soe phone numbers like 002-092-98-283 and link http://google.com,Two with soe phone numbers like 002-092-98-283 and link http://google.com,Two with soe phone numbers like 002-092-98-283 and link http://google.com,Two with soe phone numbers like 002-092-98-283 and link http://google.com", nil];
// self.tableView.estimatedRowHeight = 100;
self.tableView.rowHeight = UITableViewAutomaticDimension;
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.data count];
}
// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellID = @"CustomCell";
CustomCellTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (!cell) {
cell = [[CustomCellTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
}
cell.header.text = @"This is a header";
cell.cutomTextview.text = [self.data objectAtIndex:indexPath.row];
return cell;
}
@end
CustomTableViewcell.h
#import <UIKit/UIKit.h>
@interface CustomCellTableViewCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UITextView *cutomTextview;
@property (weak, nonatomic) IBOutlet UITextView *header;
@end
У меня была такая же проблема, потому что я назначал текст textView в viewWillAppear. Я исправил проблему, удалив назначение из viewWillApppear и добавив его в ViewDidLoad. Я думаю, что у вас такая же проблема, потому что вы назначаете текст textView в cellForRowAtIndexPath в этой строке cell.cutomTextview.text = [self.data objectAtIndex: indexPath.row]; , Я предлагаю вам попробовать установить текст только в том случае, если он пуст. Добавить проверку перед назначением, используя cell.cutomTextview.text.length – Sawsan