gpt4 book ai didi

iphone - 辞职第一响应者 UITextView

转载 作者:行者123 更新时间:2023-12-03 20:45:57 25 4
gpt4 key购买 nike

我正在使用UITEXTVIEW。我试图在按下完成按钮时发送一个 resignFirstResponder 。我不确定如何触发包含 resignFirstResponder 行的方法。

我已将 UITextView 的委托(delegate)设置为 Interface Builder 中的文件所有者。这是我的 View Controller 的 header 和实现文件:

#import <Foundation/Foundation.h>
#import "Question.h"

@interface CommentQuestionViewController : UIViewController {
Question *question;
IBOutlet UILabel *questionTitle;
IBOutlet UITextView *inputAnswer; //this is the textview
}

@property (nonatomic, retain) UILabel *questionTitle;
@property (nonatomic, retain) Question *question;
@property (nonatomic, retain) UITextView *inputAnswer;

- (void) addButton:(id)sender isLast:(BOOL)last;
- (void) setQuestionId:(NSString*)quId withTitle:(NSString*)quTitle number:(NSString*)quNum section:(NSString*)sId questionType:(NSString*)qt;

@end


#import "CommentQuestionViewController.h"


@implementation CommentQuestionViewController

@synthesize questionTitle, question, inputAnswer;

- (void) addButton:(id)delegate isLast:(BOOL)last{
UIBarButtonItem *anotherButton;
anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStylePlain target:delegate action:@selector(finishQuestionnaire:)];
self.navigationItem.rightBarButtonItem = anotherButton;
[anotherButton release];
}

-(void)viewDidLoad{
//self.questionTitle.text = question.qTitle;
[[self questionTitle] setText:[question qTitle]];
[super viewDidLoad];
NSString *str = [NSString stringWithFormat:@"Question %@", [question qNumber]];
//self.title = str;
[self setTitle:str];
[str release];
}

-(void) setQuestionId:(NSString*)quId withTitle:(NSString*)quTitle number:(NSString*)quNum section:(NSString*)sId questionType:(NSString*)qt{
question = [[Question alloc]init];
[question setQId:quId];
[question setQTitle:quTitle];
[question setQNumber:quNum];
[question setSectionId:sId];
[question setQType:qt];
}

- (void) viewWillAppear:(BOOL)animated{
self.navigationItem.hidesBackButton = YES;
}


- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
}

- (void) textViewDidEndEditing:(UITextView*)textView{
[textView resignFirstResponder];
}

- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}

- (void)dealloc {
[inputAnswer release];
[questionTitle release];
[question release];
[super dealloc];
}

最佳答案

你可以试试这个:

–(BOOL)textView:(UITextView*)textView shouldChangeCharactersInRange:(NSRange)range replacementText:(NSString*)text {
if ([text isEqualToString:@"\n"]) {
[textView resignFirstResponder];
return NO;
}
else
return YES;
}

当然,如果这样做,您将无法键入实际的回车符。

关于iphone - 辞职第一响应者 UITextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6754123/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com