UIAlertView clickedButtonAtIndex 和presentModalViewController

发布于 2024-08-25 05:22:16 字数 1163 浏览 2 评论 0原文

我正在尝试从 UIAlertView 按钮通过presentModalViewController 调用视图。代码如下,NSlog 显示在控制台中,因此我知道代码执行确实已达到该点。另外,没有错误或显示任何内容:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

if (buttonIndex != [alertView cancelButtonIndex])
{
    NSLog(@" The username is: %@ AND the password is: %@ ",textField.text,passTextField.text);

 // do some logic in here later 

    CompanyViewController *companyViewController = [[[CompanyViewController alloc] initWithNibName:@"CompanyViewController" bundle:nil] autorelease];  
    [self presentModalViewController:companyViewController animated:YES];
}
[textField resignFirstResponder];
[passTextField resignFirstResponder];

}

***** 编辑:上面的方法属于 UIViewController。以下是接口文件:

@interface testingViewController : UIViewController  <UITextFieldDelegate>
{
UITextField *textField;
UITextField *passTextField;
}
@property (nonatomic, retain) UITextField *textField;
@property (nonatomic, retain) UITextField *passTextField;
@property (readonly) NSString *enteredText;
@property (readonly) NSString *enteredPassword;

@end

如有任何帮助,我们将不胜感激。

I am trying to call a view via presentModalViewController from a UIAlertView button. The code is below, the NSlog is displayed in the console so I know that code execution is indeed reaching that point. Also, there are no errors or anything displayed:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

if (buttonIndex != [alertView cancelButtonIndex])
{
    NSLog(@" The username is: %@ AND the password is: %@ ",textField.text,passTextField.text);

 // do some logic in here later 

    CompanyViewController *companyViewController = [[[CompanyViewController alloc] initWithNibName:@"CompanyViewController" bundle:nil] autorelease];  
    [self presentModalViewController:companyViewController animated:YES];
}
[textField resignFirstResponder];
[passTextField resignFirstResponder];

}

***** Edit: The method above belongs to a UIViewController. Below is the interface file:

@interface testingViewController : UIViewController  <UITextFieldDelegate>
{
UITextField *textField;
UITextField *passTextField;
}
@property (nonatomic, retain) UITextField *textField;
@property (nonatomic, retain) UITextField *passTextField;
@property (readonly) NSString *enteredText;
@property (readonly) NSString *enteredPassword;

@end

Any help is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笑叹一世浮沉 2024-09-01 05:22:16

您可能正在尝试从不是 viewController 的东西调用presentModalViewController?例如视图。

It could be that you are trying to call presentModalViewController from something that is not a viewController? For example a View.

第七度阳光i 2024-09-01 05:22:16

只需尝试使用导航控制器不同的东西:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

  if (buttonIndex != [alertView cancelButtonIndex])
  {

      CompanyViewController *companyViewController = [[CompanyViewController alloc] init];
      UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:companyViewController];

      [self.navigationController presentModalViewController:navController animated:YES];
      [navController release];
  }

}

希望能起作用..

Just try using something different with Navigation Controller:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

  if (buttonIndex != [alertView cancelButtonIndex])
  {

      CompanyViewController *companyViewController = [[CompanyViewController alloc] init];
      UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:companyViewController];

      [self.navigationController presentModalViewController:navController animated:YES];
      [navController release];
  }

}

Hope that will work..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文