2012-09-12 3 views
1

내 프로그램에 UIActionSheet가 포함되어 있습니다. A 버튼과 B 버튼이 2 개 포함되어 있습니다. 사용자가 A 버튼을 클릭하면 다른보기로 이동합니다. 이보기에는 3 개의 텍스트 필드가 있습니다. mainviewcontroller에서이 텍스트 필드에 값을 할당하고 있습니다. 문제는 내가는 newtask에 null 값을 얻고있다 AnotherViewcontroller.miphone에서 한보기에서 다른보기로 데이터를 전달할 수 없습니다.

- (void)viewDidLoad 
    { 

       task_update.text = newtask; 
       subtask_update.text =newsubtask; 
       duedate_update.text = newduedate; 
       time_update.text = newtime; 

      NSLog(@"The task is :%@",newtask); 
       [super viewDidLoad]; 
// Do any additional setup after loading the view. 
    } 

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex: (NSInteger)buttonIndex 
    { 
     AnotherViewController *A = [[AnotherViewController alloc] init]; 

      if (buttonIndex == 1) 
      { 

       A.newtask = name; 
       A.newsubtask = sub1; 
       A.newduedate = dateName; 
       A.newtime = timeName; 


    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];                  

    UpdateViewController *viewController =[storyboard instantiateViewControllerWithIdentifier:@"update"]; 

    [self presentViewController:viewController animated:YES completion:NULL]; 


      } 
    } 

MainViewController.m

에서 그리고에

- : 나는 아래의 코드를 붙여 넣습니다. 누구든지 해결책을 말해 줄 수 있습니까? :(

답변

1

AppDelegate에 클래스에서 전역 변수를 가져 가라. 마찬가지로 AppDelegate에 .H

NSString *newtask,*newsubtask,*newduedate,*newtime; 

@property(nonatomic,retain)NSString *newtask,*newsubtask,*newduedate,*newtime; 

AppDelegate에. m

@synthesize newtask,newsubtask,newduedate,newtime; 

MainViewController.h

수입 "AppDelegate에"

{ 
AppDelegate *appDelegate; 
} 

MainViewController.m

(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex: (NSInteger)buttonIndex 
     { 
appDelegate=(AppDelegate *)[[UIApplication sharedApplication]delegate]; 
      AnotherViewController *A = [[AnotherViewController alloc] init]; 

       if (buttonIndex == 1) 
       { 

        appDelegate.newtask = name; 
        appDelegate.newsubtask = sub1; 
        appDelegate.newduedate = dateName; 
        appDelegate.newtime = timeName; 


     UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];                  

     UpdateViewController *viewController =[storyboard instantiateViewControllerWithIdentifier:@"update"]; 

     [self presentViewController:viewController animated:YES completion:NULL]; 


       } 
     } 

AnotherViewcontroller.h

수입 "AppDelegate에"

{ 
AppDelegate *appDelegate; 
} 

AnotherViewcontroller.m

- (void)viewDidLoad 
    { 
    appDelegate=(AppDelegate *)[[UIApplication sharedApplication]delegate]; 

       task_update.text = appDelegate.newtask; 
       subtask_update.text =appDelegate.newsubtask; 
       duedate_update.text = appDelegate.newduedate; 
       time_update.text = appDelegate.newtime; 

      NSLog(@"The task is :%@",newtask); 
       [super viewDidLoad]; 
// Do any additional setup after loading the view. 
    } 
+0

: 아직도 내가는 newtask에 null 값을 받고 없습니다 이니 .. :( – Div

+0

다른보기 컨트롤러에서 업데이트 코드보기 appDelegate = (AppDele 게이트 *) [[UIApplication sharedApplication] delegate]; 이 라인 뷰를 추가로드 – iSanjay

+0

않았다 : 정말 고마워요.... 그것을 가지고있어 .. :) – Div

관련 문제