请问有人可以告诉我这是怎么回事吗?
// Create the toolbar controlsUIbarbuttonItem *donebutton = [[UIbarbuttonItem alloc] initWithTitle:@"Done" style:UIbarbuttonItemStyleDone target:self action:@selector(navigationbarDonebuttonpressed:)];UIbarbuttonItem *flexibleSpace = [[UIbarbuttonItem alloc] initWithbarbuttonSystemItem:UIbarbuttonSystemItemFlexibleSpace target:nil action:nil];// Setup the toolbarnavigationToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(10.0,0.0,310.0,40.0)];[navigationToolbar setItems:@[flexibleSpace,donebutton]];// In a UItableVIEw I create a number of cells which contain UITextFIElds....// This is the method that gets called when a user presses the done button- (voID)navigationbarDonebuttonpressed:(ID)sender{ NSLog(@"Based on sender I need to access the underlying UITextFIEld.");}@H_404_16@解决方法 您可以在变量中跟踪当前聚焦的UITextFIEld,并在inputAccesoryVIEw方法中使用该变量:
在你的.h文件中:确保你符合UITextFIEldDelegate协议:
@interface MyVIEwController : UIVIEwController <UITextFIEldDelegate>
并添加此属性:
@property (assign,nonatomic) UITextFIEld *activeTextFIEld;
在.m文件中:创建动态文本字段时:
...theTextFIEld.delegate=self;...
并添加UITextFIEldDelegate协议的这些实现:
- (voID)textFIEldDIDBeginEditing:(UITextFIEld *)textFIEld{ self.activeTextFIEld = textFIEld;}- (voID)textFIEldDIDEndEditing:(UITextFIEld *)textFIEld{ self.activeTextFIEld = nil;}
现在,在inputAccesoryVIEw调用的方法中:
- (voID)navigationbarDonebuttonpressed:(ID)sender{//Just an example self.activeTextFIEld.text=@"Test";}总结
以上是内存溢出为你收集整理的ios – 如何从inputAccessoryView按钮单击获取UITextField全部内容,希望文章能够帮你解决ios – 如何从inputAccessoryView按钮单击获取UITextField所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)