Note that there are some explanatory texts on larger screens.

plurals
  1. POAutomatic placing of UITextviews under each other
    primarykey
    data
    text
    <p>i have a UITextfield, an i want to create for each insert a new UITextview with the typed Text from the UITextfield. But as you can see my Problem is that each new created Textview lays above the old Textview and i don´t know how to place the Textviews automatically under each other if i create a new one.</p> <p>My Tetxfield:</p> <pre><code>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]; </code></pre> <p>An here i create the new Textviews, right after finishing the input from the textfield:</p> <pre><code>- (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]; </code></pre> <p>}</p> <p>I hope you can help me :)</p> <p><strong>EDIT:</strong></p> <p>I now use a UITableView but i get an Error: Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to insert row 1 into section 0, but there are only 0 rows in section 0 after the update'</p> <p>My Code:</p> <pre><code>- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section { return [self.commentArray count]; </code></pre> <p>}</p> <pre><code>- (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 = @""; </code></pre> <p>}</p> <p>I only want 1 Section!</p> <p>Where is my Problem?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload