- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何在这个方法中获取textfield来调用textfieldshouldreturn?我猜它不起作用,因为 UIView 没有委托(delegate)属性,但我不确定如何使我在方法中创建的 UIView 符合协议(protocol)。我看过几篇关于授权的帖子,但我尝试过的一切都没有奏效。我确定它很简单。提前致谢。
- (void) launchCreateNewListActionSheet{
self.listActionSheet= [[UIActionSheet alloc] initWithTitle:@"Create A New List"
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
UIView *addToNewList = [[UIView alloc] initWithFrame:CGRectMake(0, 44, 320, 464)];
addToNewList.backgroundColor = [UIColor whiteColor];
UILabel *addToNewListLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 23, 100, 20)];
addToNewListLabel.text = @"List Name: ";
UITextField *enterNewListName = [[UITextField alloc] initWithFrame:CGRectMake(100, 20, 180, 30)];
enterNewListName.layer.borderWidth = 1;
enterNewListName.layer.borderColor = [[UIColor blackColor] CGColor];
enterNewListName.delegate = self;
[addToNewList addSubview:addToNewListLabel];
[addToNewList addSubview:enterNewListName];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(addToExistingList)];
UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelListPicker)];
UIBarButtonItem *fixedCenter = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
fixedCenter.width = 180.0f;
UIToolbar* toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
toolbar.barStyle = UIBarStyleBlackOpaque;
[toolbar sizeToFit];
[toolbar setItems:@[cancelBtn, fixedCenter, doneBtn] animated:YES];
[self.listActionSheet addSubview:toolbar];
[self.listActionSheet addSubview:addToNewList];
[self.listActionSheet showInView:self.view];
[self.listActionSheet setBounds:CGRectMake(0,0,320, 464)];
}
这是我的 .h 文件。我已经实现了,因为它适用于其他方法中的文本字段。
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "ZBarSDK.h"
#import "ProgressView.h"
@class ScannerViewController;
@protocol ScanViewDelegate <NSObject>;
@required
-(void)postURL:(NSURL*)url selectedAction:(NSString*)action;
@end
@interface ScannerViewController : UIViewController <ZBarReaderViewDelegate, UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate, UIWebViewDelegate, UIPickerViewDelegate, UIActionSheetDelegate>
id <ScanViewDelegate> delegate;
}
@property (weak, nonatomic) IBOutlet ZBarReaderView *readerView;
@property (weak, nonatomic) IBOutlet UITableView *scannerList;
@property (retain) id delegate;
@property (strong) NSMutableArray* barCodeArray;
@property (strong) NSMutableArray* quantityArray;
@property (strong) NSURL* url;
@property (strong) NSString* action;
@property NSString *listItems;
@property NSString *listItemNames;
@property NSArray *listItemNamesArray;
@property NSArray *hrefArray;
@property int pickerViewRow;
@property (strong) UIWebView *webView;
@property (strong) ProgressView* loading;
@property BOOL isLoading;
@property (strong) UITextField *enterNewListName;
@property (strong) UITextField *addToNewListDescription;
@property (strong) NSMutableArray *textFieldArray;
-(IBAction)sendToCart:(id)sender;
-(IBAction)sendToList:(id)sender;
-(void)startLoadingURL;
@end
这是 textfieldshouldreturn 方法:
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
if([self.textFieldArray containsObject:textField])
{
NSUInteger index = [self.textFieldArray indexOfObject:textField];
NSNumber *newQuantity = [NSNumber numberWithInteger:[textField.text integerValue]];
[self.quantityArray replaceObjectAtIndex:index withObject:newQuantity];
NSLog(@"Your new quantity is: %@", newQuantity);
}
[textField resignFirstResponder];
return YES;
}
最佳答案
这里的关键点是 Andres 想在 UIActionSheet 上使用 UiTextField。 UIActionSheet 吃水龙头的行为有点不同,实际上它阻止了对添加到操作表的 UiTextField 的健康使用。
请在发现使用自定义解决方案更好的地方查看此 SO 答案: keyboard in UIActionSheet does not type anything
基本上,最好将
UIAlertView 用于模态文本输入 View 表单 (
please see this link)
一个自定义 View ,它模仿 UIActionSheet,具有更多自定义空间(搜索例如 github as a starting point),但是有一个UIActionSheet 的解决方案也是如此。
为了将 UITextField 放置在 UIActionSheet 不钢推的 View 层次结构中,在显示 UIActionSheet 后使用此代码片段:
[self.listActionSheet addSubview:toolbar];
// [self.listActionSheet addSubview:addToNewList]; // please comment-delete this line
[self.listActionSheet showInView:self.view];
[self.listActionSheet setBounds:CGRectMake(0,0,320, 464)];
// this is the 2 new lines below
UIWindow *appWindow = [UIApplication sharedApplication].keyWindow;
[appWindow insertSubview:addToNewList aboveSubview:listActionSheet]; // you add custom view here
关于ios - 未调用 TextFieldShouldReturn,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17660222/
我有一个自定义键盘,它设置了一个 UITextInput 委托(delegate),用于将文本发送到当前文本字段。但我还需要发送一个“返回”按钮来调用 textFieldShouldReturn 方法
当前项目运行在cocos2d v2下 我有一个简单的 UITextField 添加到 CCLayer。 只要用户触摸文本字段,就会出现一个键盘。 然后当用户触摸“返回”按钮时,键盘消失并清除输入。 我
我的 textFieldShouldReturn 上有这段代码(与调用的方法不在同一个类中): - (BOOL)textFieldShouldReturn:(UITextField *)textF
如何在这个方法中获取textfield来调用textfieldshouldreturn?我猜它不起作用,因为 UIView 没有委托(delegate)属性,但我不确定如何使我在方法中创建的 UIVi
在 iPad 上,textFieldShouldReturn 不再工作。直到大约五分钟前我一直在工作,突然间不再调用该方法……有什么想法吗?下面是代码,唯一改变的是 UITextView 的通知……谢
我有两个类(class)。在其中之一中,返回键(用于虚拟键盘)完美运行。另一方面,它没有。据我所知,代码几乎相同。有人可以帮我弄清楚为什么我的那个不起作用吗? 这个有效: class ChangePa
我有一个名为 titleTextField 的 UITextField 和一个名为 save 的 UIBarButtonItem我在 viewDidload() 中设置了 titleTextField
使用多个 textField 时,不会调用 textFieldShouldReturn。 textFields 设置为数字键盘,它们应将用户输入保存到变量 textFieldEntry,但当用户点击时
当 UIscrollview 处于事件状态时,如何让用户点击屏幕时文本消失 override func touchesBegan(_ touches: Set, with event: UIEvent
抛出的异常是: 2012-09-21 00:46:56.885 Colors[3032:c07] -[UITextField value]:无法识别的选择器发送到实例 0x718cce0 2012-0
是否可以在两个不同的位置设置 textFieldShouldReturn 和 shouldChangeCharactersInRange。 目前我在一个单独的文件中使用 shouldChangeCha
有没有一种方法可以检测 -[UITextFieldDelegate textFieldShouldReturn] 是由用户按下键盘上的“完成”键(或等效键)调用的,还是由程序调用调用的到 -[UITe
我有一个 UITextField,它允许用户为 Facebook 照片输入自定义相册名称。 textFieldShouldReturn 后,我将 textField.text 发送到 Facebook
我的 TableViewController 中有一个带有搜索返回键的文本字段。 我成功地以编程方式将一些文本放入搜索文本字段中,但未能成功以编程方式运行搜索选项。 到目前为止,这是我的代码: 当我尝
我正在使用 Swift 3 开发一个应用程序,并且有两个单独的 textfields 由日期选择器分隔(不确定日期选择器是否相关)。 我想使用 textFieldShouldReturn 在用户在两个
我想让键盘在用户点击“返回”按钮时消失,我被告知要使用 -(BOOL)textFieldShouldReturn:(UITextField *)textField { [tf resignFi
根本没有调用 textFieldShouldReturn 函数:没有错误,但键盘根本没有响应。 我的情况不同于How to hide keyboard in swift on pressing ret
我想在键盘关闭后调用我的登录方法 - 因为我想开始动画并将 UIView alpha 更改为 0.5 直到响应。 - (BOOL)textFieldShouldReturn:(UITextField
我有一个 UITextField View ,当按下返回时它应该隐藏键盘。 我的功能是这样的: - (BOOL)textFieldShouldReturn:(UITextField *)textFie
从输入附件 View 中以编程方式执行(模拟)func textFieldShouldReturn(textField: UITextField) -> Bool 函数的方式是什么。 MyCustom
我是一名优秀的程序员,十分优秀!