我有textField
我希望当用户输入数据并按空格时,它应该在其中添加新行tableView
可以正常工作,但我也希望textFieldDidEndEditing
它也应该添加行但是当用户现在在我的代码中没有空格时,如果有任何用户按下空格代码,它也添加行,然后添加其他行textFieldDidEndEditing
。
-(void)textFieldDidEndEditing:(UITextField *)textField {
if (textField==tagTextField) {
[self showAnimationBack];
}
if (textField.tag==2) {
if (textField.text.length > 0 || ![tagTextField.text isEqualToString:@""]) {
[textField resignFirstResponder];
[tagArray addObject:tagInputField.text];
[tableView reloadData];
tableView.frame = CGRectMake(tableView.frame.origin.x, tableView.frame.origin.y, tableView.frame.size.width, tableView.contentSize.height);
[tableView.layer setCornerRadius:7.0f];
[tableView.layer setMasksToBounds:YES];
tableView.layer.borderWidth = 0.5;
tableView.layer.borderColor = [UIColor grayColor].CGColor;
[self showAnimationBack];
float y = descriptionTextImageView.frame.origin.y;
float yp = publishButton.frame.origin.y;
NSLog(@"Y is %2.f",y);
if (y==405.00) {
[descriptionTextImageView setFrame:CGRectMake(48,y+30,250,90)];
[publishButton setFrame:CGRectMake(40,yp+30,250, 50)];
}
else{
y=y+30;
[descriptionTextImageView setFrame:CGRectMake(48,y,250,90)];
[publishButton setFrame:CGRectMake(40,yp+30,250, 50)];
}
}
}
}
按下空格时的其他
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if (textField.tag==2) {
if ( [string isEqualToString:@" " ]){
if (textField.text.length > 0 || ![tagTextField.text isEqualToString:@""]) {
[textField resignFirstResponder];
[tagArray addObject:tagInputField.text];
[tableView reloadData];
tableView.frame = CGRectMake(tableView.frame.origin.x, tableView.frame.origin.y, tableView.frame.size.width, tableView.contentSize.height);
[tableView.layer setCornerRadius:7.0f];
[tableView.layer setMasksToBounds:YES];
tableView.layer.borderWidth = 0.5;
tableView.layer.borderColor = [UIColor grayColor].CGColor;
float y = descriptionTextImageView.frame.origin.y;
float yp = publishButton.frame.origin.y;
NSLog(@"Y is %2.f",y);
if (y==405.00) {
[descriptionTextImageView setFrame:CGRectMake(48,y+30,250,90)];
[publishButton setFrame:CGRectMake(40,yp+30,250, 50)];
}
else{
y=y+30;
[descriptionTextImageView setFrame:CGRectMake(48,y,250,90)];
[publishButton setFrame:CGRectMake(40,yp+30,250, 50)];
}
[self showAnimationBack];
}
}
else {
return YES;
}
}
}