UIAlertView clickedButtonAtIndex 和presentModalViewController
我正在尝试从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能正在尝试从不是 viewController 的东西调用presentModalViewController?例如视图。
It could be that you are trying to call presentModalViewController from something that is not a viewController? For example a View.
只需尝试使用导航控制器不同的东西:
希望能起作用..
Just try using something different with Navigation Controller:
Hope that will work..