UITextField becomeFirstResponder and overlap subviews
I have two problems. I create a class "myfirstclass.m" and in my "projectController.m" I create a UITextField txt. In "myfirstclass.m" I have a method that take txt as parameter. If inside the class I call the method:
[txt becomeFirstResponder];
It doesn't works. Obviously "myfirstclass.m" extends NSObject and "projectController.m" extends UIViewController. How can I solve? because in the same class "myfirstclass.m" I have another method that create another UITextField that is add to the principal view, and when It is showed this current textField become the First Responder.
My second problem is: I have an UIButton and a UITextField, I add them to ad view, I want that: UITextField is showed in foreground and the UIButton in background. I now that by a property of UITextFiled can I set a background image, but I want that the UIButon that is bigger than UITextField, but I want that UIButton is background and UITextField the foreground.
Thanks in advance开发者_JAVA百科!
To the first question: I'm assuming you're using interface builder. Make sure your UITextField is connected to the corresponding outlet of your UIViewController subclass. Forgetting to connect outlets in interface builder is the most common problem for objects not appearing on the screen or not responding properly in code.
This is a sample pseudo-code:
projectController.m
#import "myFirstClass.h"
UITextField *txt = [[UITextField alloc] initWithFrame:CGRectMake(0,38,194,37)];
myFirstClass *ojb = [[myFirstClass alloc] init];
[obj sendTxt:txt];
myFirstClass.m
- (void) sendTxt:(UITextField *text) {
UITextField *txt = text;
[txt becomeFirstResponder];
}
"myfirstclass.m" extends NSObject and "projectController.m" extends UIViewController.
精彩评论