У меня есть UITextfield, я хочу создать для каждой вставки новое UITextview с введенным текстом из поля UITextfield. Но, как вы видите, моя проблема в том, что каждый новый созданный Textview лежит над старым Textview, и я не знаю, как разместить Textviews автоматически друг под другом, если я создаю новый.Автоматическое размещение UITextviews под друг друга
Мои Tetxfield:
self.inputComment = [[GTTextField alloc]initWithFrame:CGRectMake(0,self.mainView.frame.origin.y + self.mainView.frame.size.height - 100.0f, self.frame.size.width, 100.0f)];
self.inputComment.placeholder = @"Answer";
self.inputComment.font = GTDefaultTextFont;
self.inputComment.textColor = GTDefaultTextColor;
self.inputComment.userInteractionEnabled = YES;
self.inputComment.returnKeyType = UIReturnKeyDone;
[self.inputComment resignFirstResponder];
self.inputComment.delegate = self;
[self.mainView addSubview: self.inputComment];
здесь я создать новый TextViews, сразу после окончания ввода из текстового поля:
- (void)textFieldDidEndEditing:(UITextField *)textField{
NSString *saveText = self.inputComment.text;
self.containerCommentView = [[[GTView alloc] initWithFrame:CGRectMake(0.0f,self.messageView.frame.origin.y + self.messageView.frame.size.height,self.frame.size.width, 100.0f)] autorelease];
self.containerCommentView.backgroundColor = [UIColor lightGrayColor];
[self.scrollView addSubview: self.containerCommentView];
self.commentImageView = [[[GTImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f,50, 50.0f)] autorelease];
[self.containerCommentView addSubview:self.commentImageView];
self.commentView = [[[GTTextView alloc] initWithFrame:CGRectMake(50.0f, 0.0f,270.0f, 100.0f)] autorelease];
self.commentView.userInteractionEnabled = NO;
self.commentView.textColor = [UIColor blackColor];
self.commentView.backgroundColor = [UIColor lightGrayColor];
[self.commentView setText: saveText];
[self.containerCommentView addSubview: self.commentView];
}
Я надеюсь, что вы можете мне помочь:)
EDIT:
Теперь я использую UITableView, но получаю сообщение об ошибке: Завершение приложения из-за неотображенного исключения «NSInternalInconsistencyException», причина: «попытаться вставить строку 1 в раздел 0, но после обновления только 0 строк в разделе 0 '
Мой код:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section {
return [self.commentArray count];
}
- (void)buttonTapped:(id)sender {
[self.tableView beginUpdates];
int rowIndex = self.commentArray.count;
[self.commentArray insertObject:[[NSString alloc] initWithFormat:@"%@", self.inputComment.text]
atIndex:rowIndex];
// Notify UITableView that updates have occurred
NSArray *insertIndexPaths = [NSArray arrayWithObject:
[NSIndexPath indexPathForRow:rowIndex inSection:0]];
[self.tableView insertRowsAtIndexPaths:insertIndexPaths
withRowAnimation:UITableViewRowAnimationRight];
[self.tableView endUpdates];
self.inputComment.text = @"";
}
Я хочу только 1 секцию!
Где моя проблема?
Спасибо за отличный совет !! , я попробовал его с UITableView, но теперь я получаю некоторые проблемы .... см. мое редактирование – Davis
Ответ обновлен, чтобы отразить ваши изменения. –
Спасибо, теперь он отлично работал :) – Davis