【发布时间】:2013-07-24 15:38:36
【问题描述】:
我有一个 UITextfield,我想为每个插入一个新的 UITextview 创建一个带有来自 UITextfield 的输入文本。但是正如您所看到的,我的问题是每个新创建的 Textview 都位于旧 Textview 之上,如果我创建一个新的,我不知道如何将 Textviews 自动放置在彼此之下。
我的 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];
在完成文本字段的输入后,我在这里创建了新的 Textview:
- (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];
}
我希望你能帮助我:)
编辑:
我现在使用 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 个部分!
我的问题在哪里?
【问题讨论】:
标签: iphone objective-c uitextfield uitextview uitextfielddelegate