gpt4 book ai didi

ios - 关于 iOS 中 Popup Window 的 UITextView

转载 作者:行者123 更新时间:2023-11-29 01:36:35 25 4
gpt4 key购买 nike

我有UIViewController Manager

@interface Manager : UIViewController

@property NSString *currentNameID;


@end

@interface Manager ()<UITextFieldDelegate>{
sqlite3 *RECORDS;
sqlite3_stmt *statement;
NSString *databasePath;
NSString *docsDir;
NSArray *dirPaths;


}

在管理器中 UIViewController , 我想创建一个弹出窗口。它被创建为

-(void)createPopUpWindow
{
//Component specs
int gap = 20;//to update
int bigButtonWidth = 70;//to update
int componentverHeight = 40;//to update

int numcomponentsvertically = 4;
int numcomponentshorizontally = 3;
int textViewW = bigButtonWidth*2;
int smallButtonWidth = 20;
int uiviewWidth = gap * 4 + bigButtonWidth * numcomponentshorizontally;
int uiviewHeight = gap * 5 + componentverHeight * numcomponentsvertically;
// create view popup
int centerx = (int)(self.view.bounds.size.width / 2);
int centery = (int)(self.view.bounds.size.height / 2);

//Popup window
int x = centerx - (int)(uiviewWidth/2);
int y = centery - (int)(uiviewHeight/2);
self.viewPopup = [[UIView alloc] initWithFrame:CGRectMake(x, y, uiviewWidth, uiviewHeight)];
self.viewPopup.backgroundColor = [UIColor grayColor];
[self.view addSubview:self.viewPopup];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(dismissKeyboard)];

[self.viewPopup addGestureRecognizer:tap];



self.idTextView = [[UITextView alloc] initWithFrame:CGRectMake(gap, gap, textViewW, componentverHeight)];
[self.idTextView setReturnKeyType:UIReturnKeyDone];
self.idTextView.restorationIdentifier = @"idview";
self.idTextView.delegate = self.viewPopup;
[self.viewPopup addSubview: self.idTextView];

}

-(void)dismissKeyboard {
if([self.currTextfield isEqualToString:@"idview"]){
[self.idTextView resignFirstResponder];
}
}

然后我还需要 UITextView 的回调函数来获取有关 UITextView 的一些信息,例如

    - (BOOL) textFieldShouldBeginEditing: (UITextField *) textField
{
textField.text = @"";
self.currTextfield = textField.restorationIdentifier;
}

现在回调函数在弹出窗口中不起作用。我把<UITextFieldDelegate>在经理处,如上所示。但它不起作用。

如何让它工作以便调用 UITextView 的回调?然后在这一行中,应该分配给谁来委托(delegate) self.idTextView.delegate = self.viewPopup;谢谢

最佳答案

您的代码中有多个错误:

  1. 您正在使用 UITextView 并将协议(protocol)设置为 UITextFieldDelegate。要么制作 UITextViewDelegate 要么更改 UITextField

如果您使用UITextViewDelegate,则应使用以下委托(delegate)方法:

- textViewShouldBeginEditing:
- textViewDidBeginEditing:
- textViewShouldEndEditing:
- textViewDidEndEditing:

  1. 您正在将协议(protocol)设置为自类,因此需要更改代码行:self.idTextView.delegate = self;

关于ios - 关于 iOS 中 Popup Window 的 UITextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32900599/

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