0
我有一個登錄控制器,成功登錄後,我想將某個字符串值傳遞給菜單頁。但是它不起作用。應用程序崩潰。 我試圖Ihuk和SAM的可能的寶貴意見,從下面的鏈接如何將字符串值從一個控制器傳遞到另一個控制器
how to pass a string value from one view controller to another view controller
loginController.h:
#import <UIKit/UIKit.h>
@class RootViewController;
@class Menu;
@interface LoginController : UIViewController {
UIButton *login_Button;
UITextField *username_TextField;
UITextField *password_TextField;
RootViewController *mc1;
UINavigationController *navigationController;
Menu *mv1;
}
@property(nonatomic,retain) IBOutlet UIButton *login_Button;
@property(nonatomic,retain) IBOutlet UITextField *username_TextField;
@property(nonatomic,retain) IBOutlet UITextField *password_TextField;
@property(nonatomic,retain) RootViewController *mc1;
@property (nonatomic, retain) IBOutlet
UINavigationController *navigationController;
@property(nonatomic,retain)Menu *mv1;
- (IBAction)Login_Method:(id)sender;
-(id)initWithUserName:(NSString *)name ;
@end
loginController.m
#import "LoginController.h"
#import "Menu.h"
#import "ViewController.h"
#import "RootViewController.h"
@implementation LoginController
@synthesize mc1,mv1;
@synthesize login_Button,username_TextField,password_TextField;
@synthesize navigationController;
// Implement viewDidLoad to do additional setup after
// loading the view, typically from a nib.
- (void)viewDidLoad {
if (![self.navigationController isNavigationBarHidden])
[self.navigationController setNavigationBarHidden:YES animated:NO];
//[self presentModalViewController:navigationController animated:YES];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (IBAction)Login_Method:(id)sender
{
Menu *mv2 = [[Menu alloc] initWithUserName:@"Menu" bundle:nil];
//[email protected]"aa"; //i tried this, but not work,so created initWithUserName
self.mv1=mv2;
[self presentModalViewController:mv1 animated:YES];
// [RootViewController release];
}
-(id)initWithUserName:(NSString *)name
{
self = [super init];
if (nil == self) {
return nil;
}
// display or store login info somewhere
[mv1.l1 setText:name];
return self;
}
-(BOOL)textFieldShouldReturn:(UITextField *)theTextField {
[theTextField resignFirstResponder];
return YES;
}
- (void)dealloc {
[username_TextField release];
[password_TextField release];
[super dealloc];
}
@end
Menu.h
#import <UIKit/UIKit.h>
@class Menu;
@interface Menu : UIViewController {
UILabel *l1;
UIButton *AccountSummary_Button;
UIButton *PayOffQuote_Button;
UIButton *PayBill_Button;
UIButton *Logout_Button;
UINavigationController *nv1;
}
@property(nonatomic,retain) IBOutlet UILabel *l1;
@property(nonatomic,retain) IBOutlet UIButton *AccountSummary_Button;
@property(nonatomic,retain) IBOutlet UIButton *PayOffQuote_Button;
@property(nonatomic,retain) IBOutlet UIButton *PayBill_Button;
@property(nonatomic,retain) IBOutlet UIButton *Logout_Button;
@property (nonatomic, retain) IBOutlet UINavigationController *nv1;
-(IBAction)ViewAccountSummary_method:(id)sender;
-(IBAction)ViewPayOffQuote_method:(id)sender;
-(IBAction)ViewPayBill_method:(id)sender;
-(IBAction)Logout_method:(id)sender;
@end
Menu.m
使用4個空格縮進代碼,以使其格式正確。閱讀http://stackoverflow.com/editing-help以獲取更多信息(也可通過點擊答案輸入字段上方的橙色問號來訪問) – outis 2009-11-07 17:36:03
在模擬器中運行它時,請轉到運行,控制檯。然後繼續登錄並讓應用程序崩潰。控制檯底部記錄的錯誤是什麼? – marcc 2009-11-07 19:02:39
這是一個重複的:http://stackoverflow.com/questions/1692984/pass-a-string-value-from-one-view-controller-to-another – 2009-11-07 19:19:39