0

我是 Objective-C 的新手,并在某一点上受到打击。

我创建了一个基于视图的应用程序并将 tabbarController(拖放)放在 mainwindow.xib 上......因为它是一个 ViewBasedApplication 所以我的 ViewController 直接从 AppDelegate 启动。我在 ViewController 中有一个 UItextField ..现在当应用程序启动时我可以看到 UItextField ,TabBar 有两个标签栏项目。但是当我触摸 UItextField 并尝试输入一些字符时,我在 UITextField 上看不到光标,因此我无法输入任何字符。所以我希望 UItextField 在我触摸它时做出响应。

我该怎么做 ?

4

2 回答 2

0

应用委托文件:

 // Create instance of UINavigationController
    UINavigationController *myNavigationController;
    // Create initialized instance of UITabBarController
    UITabBarController *tabBarController = [[UITabBarController alloc] init];
    // Create initialized instance of NSMutableArray to hold our UINavigationControllers
    NSMutableArray *tabs = [[NSMutableArray alloc] init];

    // Create first UIViewController
    UIViewController *myFirstViewController = [[UIViewController alloc] init];
    [myFirstViewController setTitle:@"First"];
    // Initialize the UINavigationController
    myNavigationController = [[UINavigationController alloc] initWithRootViewController:myFirstViewController];
    // Add UINavigationController to you tabs
    [tabs addObject:myNavigationController];
    // Release UIViewController and UINavigationController
    [myFirstViewController release], [myNavigationController release];

    // Create second UIViewController
    UIViewController *mySecondViewController = [[UIViewController alloc] init];
    [mySecondViewController setTitle:@"Second"];
    // Initialize the UINavigationController
    myNavigationController = [[UINavigationController alloc] initWithRootViewController:mySecondViewController];
    // Add UINavigationController to you tabs
    [tabs addObject:myNavigationController];
    // Release UIViewController and UINavigationController
    [mySecondViewController release], [myNavigationController release];

    // Add the tabs to the UITabBarController
    [tabBarController setViewControllers:tabs];
    // Add the view of the UITabBarController to the window
    self.window.rootViewController = tabBarController;

[self.window makeKeyAndVisible];

ViewController.h 文件:

  • 在 .h 文件中

UITextField *textfld;

  • 在 .m 文件中:

viewDidLoad 方法:

    textfld = [[UITextField alloc] initWithFrame:<Frame>]; 
    textfld.delegate = self; 
    [textfld becameFirstResponder];

使您的 .h 文件 textfielddelegate 使用

 @interface YourClassName:UIViewController <UITextFieldDelegate>.

希望对你有效。

于 2012-10-26T07:13:38.143 回答
0

尝试使用这个

[textfld setUserInteractionEnabled:YES];
于 2012-10-26T07:39:26.303 回答