2010-03-13 45 views
0

我想从UIAlertView按钮调用一个通过presentModalViewController的视图。代码如下,NSlog显示在控制台中,所以我知道代码执行确实达到了这一点。此外,没有错误或任何显示:UIAlertView clickedButtonAtIndex with presentModalViewController

- (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 

任何帮助表示赞赏。

+0

请问这种方法属于视图或视图控制器? – 2010-03-13 23:17:21

+0

是您的名为CompanyViewController.nib或CompanyView.nib的nib吗? (我用'initWithNibName'自己犯了几次错误)。 – 2010-03-14 06:17:21

+0

嗨。我只加倍检查了我的项目 - 笔尖是CompanyViewController.nib。谢谢你的评论。 – CraigH 2010-03-14 06:36:58

回答

0

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

+0

嗨,我刚刚编辑了我的问题 - 谢谢。 该方法属于viewController。 – CraigH 2010-03-14 06:07:24

0

刚刚尝试使用带有导航控制器不同的东西:

- (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]; 
    } 

} 

希望将工作..

相关问题