UITextField 的隐藏属性不起作用
在我的 iPhone/iPad 应用程序(在 Objective-C 中)中,有一些 UITextFields
我正在以编程方式添加它们,并将它们进一步添加到数组中。
我想在某些按钮单击时设置 hidden
属性(我通过遍历数组找到了特定的 UITextField
)。
当我设置 textfilled.hidden = true
(在按钮单击事件时),那么它不会隐藏,而是在禁用模式下,如果我再次设置 textfilled.hidden = false
,然后它就可以了。
我尝试过在同一级别更改其他属性,例如文本、背景颜色等,除了隐藏属性之外,所有属性都工作正常。
注意:如果在添加文本字段(与 UITextField
具有相同的对象)后设置 textfilled.hidden = true
,那么它会完美隐藏。
更新:我使用了以下代码:
UITextField *textField=[[[UITextField alloc] initWithFrame:CGRectMake(lastPoint.x, lastPoint.y, 60, 20)] autorelease];
textField.backgroundColor=[UIColor greenColor];
textField.textColor=[UIColor blackColor];
[textField addTarget:self action:@selector(handleEnterPressed:) forControlEvents:UIControlEventEditingDidEndOnExit];
[capturedImage addSubview:textField];
[noteTextArray addObject:textField];
在此我创建一个 UITextField 并将其添加到数组(noteTextArray)并在此处调用 .hidden 属性:
-(void)handleEnterPressed:(UITextField *)textField
{
for(UITextField *noteText in noteTextArray)
{
if(noteText.tag==textField.tag)
{
noteText.backgroundColor=[UIColor purpleColor];
noteText.text=@"Hi";
noteText.hidden=true;
}
}
}
但它并没有隐藏文本字段。
如果有人有任何想法或解决方案,请告诉我。
更新1:图像已通过捕获WebView当前视图的屏幕截图来获取
UIGraphicsBeginImageContextWithOptions(webview.frame.size,NO,0.0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
[webview.layer renderInContext: context];
capturedImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
,并且图像进一步添加到uiscrollviewer:
scrollViewer.delegate=self;
scrollViewer.contentOffset = CGPointZero;
capturedImage.contentMode= UIViewContentModeScaleAspectFit;
scrollViewer.userInteractionEnabled=true;
scrollViewer.contentMode= UIViewContentModeScaleAspectFit;
scrollViewer.scrollEnabled=YES;
[scrollViewer setBouncesZoom:YES];
scrollViewer.clipsToBounds= YES;
scrollViewer.contentSize = capturedImage.image.size;
scrollViewer.minimumZoomScale=0.1;
scrollViewer.maximumZoomScale=5.0;
scrollViewer.zoomScale=0.5;
if(capturedImage.superview != scrollViewer)
{
[scrollViewer addSubview:capturedImage];
}
In my app for iPhone/iPad (in Objective-C), there are some UITextFields
which I am adding progrmatically and these further added to array.
I want to set the hidden
property on some button click (where I found the particular UITextField
by traversing the array).
When I set the textfilled.hidden = true
(at button click event), then it is not hidden instead in disabled mode and if I again set textfilled.hidden = false
, then it enables.
I have tried changing other properties like text, background color etc. at the same level all works fine except the hidden property.
Note: If it set textfilled.hidden = true
after adding the text field (with the same object of UITextField
) then it hides perfectly.
UPDATE: I have used the following code:
UITextField *textField=[[[UITextField alloc] initWithFrame:CGRectMake(lastPoint.x, lastPoint.y, 60, 20)] autorelease];
textField.backgroundColor=[UIColor greenColor];
textField.textColor=[UIColor blackColor];
[textField addTarget:self action:@selector(handleEnterPressed:) forControlEvents:UIControlEventEditingDidEndOnExit];
[capturedImage addSubview:textField];
[noteTextArray addObject:textField];
In this I am creating a UITextField and adding it to array(noteTextArray) and the calling the .hidden property here:
-(void)handleEnterPressed:(UITextField *)textField
{
for(UITextField *noteText in noteTextArray)
{
if(noteText.tag==textField.tag)
{
noteText.backgroundColor=[UIColor purpleColor];
noteText.text=@"Hi";
noteText.hidden=true;
}
}
}
But it is not hiding the text field.
Please let me know if somebody has any idea or solution.
UPDATE 1: Image has been taken by capturing the screenshot of current view of WebView
UIGraphicsBeginImageContextWithOptions(webview.frame.size,NO,0.0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
[webview.layer renderInContext: context];
capturedImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
And the image further added to uiscrollviewer:
scrollViewer.delegate=self;
scrollViewer.contentOffset = CGPointZero;
capturedImage.contentMode= UIViewContentModeScaleAspectFit;
scrollViewer.userInteractionEnabled=true;
scrollViewer.contentMode= UIViewContentModeScaleAspectFit;
scrollViewer.scrollEnabled=YES;
[scrollViewer setBouncesZoom:YES];
scrollViewer.clipsToBounds= YES;
scrollViewer.contentSize = capturedImage.image.size;
scrollViewer.minimumZoomScale=0.1;
scrollViewer.maximumZoomScale=5.0;
scrollViewer.zoomScale=0.5;
if(capturedImage.superview != scrollViewer)
{
[scrollViewer addSubview:capturedImage];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用 alpha 属性。
隐藏:
再次显示:
You can use alpha property.
To hide:
To show again:
属性无法设置为活动和停用,因此如果您根据按下按钮 1
和按下按钮时
等情况设置属性,这将是更好的方法更新:
更新 2:
更新 3:请下载 示例代码 (testTextField)
Property cannot set as active and deactivate so This will be better approach if u set the property according to the situation like on button 1 pressed
and on button pressed
update:
Update 2:
update 3: please download the sample code (testTextField)
我刚刚在我的项目中尝试了你的代码,它运行完美。一开始它就不起作用,因为我没有分配 noteTextArray。
因此,调试并检查 UIControlEventEditingDidEndOnExit 上的控件是否移动到方法“handleEnterPressed”,就是这样。如果它在handleEnterPressed中并且noteTextArray不为空,那么将正常工作,隐藏属性没有任何问题。我已经告诉过你问题出在其他地方。
所以检查 noteTextArray 是否为空
I just tried your code in my project, its working perfect. on very start it was not working because i didn't allocated noteTextArray.
so debug and check whether on UIControlEventEditingDidEndOnExit control moves to Method "handleEnterPressed", that's it. If it is in handleEnterPressed and noteTextArray is not empty then will work fine, there is nothing wrong with hidden property. I already told you problem is somewhere else.
so check whether noteTextArray is empty or not
无需进行标签检查 - 您拥有发件人中的所有信息。
您可能想像这样更改您的委托方法:
并在控制台中检查您的委托方法是否被调用。
There's no need for tag checking - you have all the information in sender.
You might want to change your delegate method like this:
And check in console if your delegate method is called at all.