我有导航控制器的两个视图:第一个视图中,有空文本字段,而第二个视图是用户可以选择行的表视图。只需触摸一行,就会为第一个视图的文本字段设置一个值。不幸的是,当我回到第一个视图字段没有设置。将值传递给第一个视图的文本字段
这是我的代码:
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