我有導航控制器的兩個視圖:第一個視圖中,有空文本字段,而第二個視圖是用戶可以選擇行的表視圖。只需觸摸一行,就會爲第一個視圖的文本字段設置一個值。不幸的是,當我回到第一個視圖字段沒有設置。將值傳遞給第一個視圖的文本字段
這是我的代碼:
FirtViewController.h
@interface FirstViewController : UIViewController
{
UITextField *firstField;
UITextField *secondField;
}
@property(nonatomic, retain) IBOutlet UITextField *firstField;
@property(nonatomic, retain) IBOutlet UITextField *secondField;
@property(copy) NSString *selectedRow;
-(IBAction)showTable:(id)sender
FirstViewController.m
#import "FirstViewController.h"
#import "AppDelegate.h"
#import "SecondViewController.h"
@implementation FirstViewController
@synthesize .....
.............
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
self.firstField.text = selectedRow;
}
-(IBAction)showTable:(id)sender
{
SecondViewController *controllerSecond = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
[self.navigationController pushViewController:controllerSecond animated:YES];
}
SecondViewController.h
@class FirstViewController;
@interface ListaViewController : UIViewController
<UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate>
{
UITableView *table;
UISearchBar *search;
FirstViewController *controller;
}
@property (nonatomic, retain) FirstViewController *controller;
SeconViewController.m
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *selectedRow = [tableData objectAtIndex:indexPath.row];
controller.selectedRow = selectedRow;
[self.navigationController popViewControllerAnimated:YES];
}
請在FirstViewController中顯示。你加載SecondViewController。這是您必須將SecondViewController重新連接到First的地方。 – Walter 2011-12-23 16:33:37
請參閱上面,我把這個請求 – Maurizio 2011-12-23 16:56:34