2011-12-23 3 views
0

내 응용 프로그램에는 두 가지보기가 있습니다. 주보기에는 사용자가 입력해야하는 입력 필드와 두 번째보기에 연결된 단추가 있습니다. 두 번째보기에는 테이블보기가 있는데, 사용자가 행을 선택하면 자동으로 기본보기로 돌아갑니다. 내 문제는 기본보기로 돌아 가면 텍스트 필드의 값이 지워진다는 것입니다. 모든 솔루션? 감사합니다.텍스트 필드에 값 지정 firstview of secondview

두 번째보기 헤더

@class MainViewController; 

    @interface ListaViewController : UIViewController 
    <UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate> 
    { 
     UITableView *table; 
     UISearchBar *search; 
     MainViewController *child; 
    } 

    @property (nonatomic, retain) IBOutlet UITableView *table; 
    @property (nonatomic, retain) IBOutlet UISearchBar *search; 
    @property (nonatomic, retain) MainViewController *child; 


    - (IBAction)switchBack:(id)sender; 

두 번째보기 구현 :

 -(IBAction)switchBack:(id)sender 
     { 
     child.selectedCountry = selectedCountry; 
     child.codiceComune = codiceComune; 
     [self.navigationController popViewControllerAnimated:YES]; 
     } 

먼저보기 :

 -(void)viewDidAppear:(BOOL)animated 
     { 
     [super viewDidAppear:animated]; 
     cityField.text = selectedCountry; 
     } 

이 작동하지!

답변

0

코드없이 추측하면 viewDidLoad, viewDidAppear 또는 viewWillappear에서 텍스트 필드를 비우거나 초기화 할 수 있습니다. 대신 viewController init에서 수행하십시오.

+0

ViewController를 다시 작성하고 있습니다. 어떤 텍스트 필드를 다시 만들고 있습니다. 다시 원래의 viewController로 다시 전환해야합니다. – ader

1
-(IBAction)switchBack:(id)sender 
     { 
     MainViewController *controller = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil]; 
     controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
     [self presentModalViewController:controller animated: YES]; 
     [controller release]; 
     } 

그것은 당신이 이전으로 돌아가, 새로운 MainViewController을하지 만들 것을 의미한다. 이 코드 대신

-(IBAction)switchBack:(id)sender 
{ 
    [self dismissModalViewControllerAnimated:YES]; 
} 

P.S.

사용 두 번째 vievcontroller에 글을 쓰는 것과 같은 방식으로 작동하면 작동합니다. -(IBAction)switchBack:(id)sender

+0

Thk,하지만 문제가 있습니다. controller.selectedCountry = selectedCountry를 사용하여 기본보기로 값을 전달했습니다. controller.code = code; – Maurizio

+0

@Maurizio 그것은 당신이 일을 잘못하고 있음을 의미합니다. 당신은 새로운 MainController를 생성 할 필요가 없다. 이전에이 값을 변경하기 만하면된다. 예를 들어 SecondControl에서 MainController를 변수로 보내고 속성을 변경하기 전에 속성을 변경할 수 있습니다. – Padavan

+0

thk. 두 번째보기에서 값을 가져 와서 첫 번째보기에 값을 할당하는 방법? 만약 내가 일을하지 않으면 간단한 해고를 사용합니다. – Maurizio

관련 문제