2011-11-01 55 views
-1

我正在申請爲我有兩個頁面:如何將測試值從一個視圖傳遞到其他視圖?

第1頁

在我所1個文本框,一個提交按鈕。

當用戶在文本字段中輸入值時,輸入到文本文件中的值應顯示在下一頁上。

第2頁有 1文本框顯示的數值,在第一頁中輸入和編輯按鈕,編輯文本,如果他想的

,如果他在編輯按鈕,點擊他應該移動到一個頁面,是他可以看到,他已經進入了價值,應改變

我能夠從一個頁面傳遞文本字段值等,但不能顯示在一個頁面上相同的值當用戶單擊編輯按鈕..

以下是我的page1.h文件

#import <UIKit/UIKit.h> 
#import "new.h" 

@interface tryViewController : UIViewController { 

IBOutlet UITextField *textField; 

} 

@property(nonatomic,retain)IBOutlet UITextField *textField; 

-(IBAction)submit; 

@end 

以下是我的第1頁.m文件:

#import "tryViewController.h" 

@implementation tryViewController 

@synthesize textField; 



- (BOOL)textFieldShouldReturn:(UITextField *)theTextField { 

    [theTextField resignFirstResponder]; 

    return YES; 
} 


- (void)viewDidUnload { 

    // Release any retained subviews of the main view. 

    // e.g. self.myOutlet = nil; 
} 


- (void)dealloc { 

    [super dealloc]; 

} 


-(IBAction)submit 

{ 

    new *pg = [new alloc]; 
    pg.str = textField.text; 
    [self .view addSubview:pg.view]; 
    [self presentModalViewController:pg animated:YES]; 
} 

@end 

以下是我的第2頁.h文件中:

#import <UIKit/UIKit.h> 
#import "tryViewController.h" 

@interface new : UIViewController { 

    IBOutlet UITextField *txtField; 

    NSString *str; 

} 
@property(nonatomic,retain)IBOutlet UITextField *txtField; 

@property(nonatomic,retain)NSString *str; 

-(IBAction)back; 


@end 


following is my page2 .m file: 


#import "new.h" 


@implementation new 
@synthesize str; 


- (void)viewDidLoad { 


    txtField.text = str; 

    [super viewDidLoad]; 

} 





- (void)dealloc { 
    [super dealloc]; 
} 

-(IBAction)back 
{ 
} 


@end 

回答

0

你的代碼是...奇怪。 嘗試使用以大寫字母開頭並帶有人類可讀名稱的類名。

爲什麼使用模態視圖控制器代替導航控制器?

嘗試這種代碼:

EditViewController.h

#import <UIKit/UIKit.h> 
#import "ShowViewController.h" 

@interface EditViewController : UIViewController { 
    IBOutlet UITextField *textField; 
} 

@property(nonatomic,retain)IBOutlet UITextField *textField; 

-(IBAction)submit; 
@end 

EditViewController.m

#import "EditViewController.h" 

@implementation EditViewController 

@synthesize textField; 

- (BOOL)textFieldShouldReturn:(UITextField *)theTextField { 
    [theTextField resignFirstResponder]; 
    return YES; 
} 

- (void)viewDidUnload { 
    // Release any retained subviews of the main view. 
    self.textField = nil; 
} 

- (void)dealloc { 
    [super dealloc]; 
} 

-(IBAction)submit { 
    ShowViewController *showViewController = [[ShowViewController alloc] initWithNibName:@"ShowViewController" bundle:nil]; 
    showViewController.string = textField.text; 
    [self.navigationController pushViewController:showViewController animated:YES]; 
} 

@end 

ShowViewController.h

#import <UIKit/UIKit.h> 

@interface new : ShowViewController { 

} 

@property(nonatomic,retain)IBOutlet UITextField *txtField; 
@property(nonatomic,retain)NSString *string; 

-(IBAction)back; 

@end 

ShowViewController.m

#import "ShowViewController.h" 

@implementation ShowViewController 
    @synthesize string; 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    txtField.text = string; 
} 

- (void)dealloc { 
    [super dealloc]; 
} 

-(IBAction)back { 
    [self.navigationController popViewControllerAnimated:YES]; 
} 

@end 

在您的MainWindow.xib添加導航控制器(或創建與導航控制器嚮導項目。

如果你不想要NAB酒吧只是在你的應用程序委託添加

[navigationController setNavigationBarHidden:YES animated:NO]; 

+0

好的,我會試試....謝謝 – Nilesh

+0

謝謝mr.Mathieu Hausherr .....工作的 – Nilesh

+0

謝謝mr.mathieu – 2013-04-09 10:18:12

相關問題