Мне помогал другой человек в StackOverflow. Они показали мне пример, который позволит мне разместить текст в UITextView
, который затем автоматически отображается в UITableView
. Он отлично работает на его стороне, однако по какой-то причине на моей стороне ничего не происходит.TextView не обновляет TableView
Heres код.
.h
@interface ViewController : UIViewController <UITableViewDataSource,UITableViewDelegate,UITextViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UITextView *txtView;
.m
@interface ViewController()<UITableViewDataSource,UITableViewDelegate,UITextViewDelegate> {
NSMutableArray *listArray;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 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)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [NSString stringWithFormat:@"%@",[listArray objectAtIndex:indexPath.row]];;
return cell;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return listArray.count;
}
-(void)textViewDidChange:(UITextView *)textView{
listArray=[[NSMutableArray alloc]initWithArray:[textView.text componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]]];
[self.tableView reloadData];
NSLog(@"Array-- %@",listArray);
NSLog(@"Array Count-- %lu",(unsigned long)listArray.count);
NSLog(@"Text-- %@",textView.text);
}
Спасибо за помощь.
ли все делегаты и DataSource для Tableview и TextView настройки правильно в XIb/раскадровке? –
Какой делегат мне нужно подключить? – vype
перейти к XIB, подключить табличное представление с делегатами и источниками данных. Вы также можете добавить точку останова, чтобы проверить, работают ли методы просмотра таблицы. –