How to pass a textfiled value from one view to any other view xcode

前端 未结 3 438
北海茫月
北海茫月 2021-01-26 10:53

I have to pass a UITextField value from one view to other views(2nd,3rd...views).Actually in my 3rd ViewController I have a scrollView and I have to display value on it .But UIT

3条回答
  •  生来不讨喜
    2021-01-26 11:42

    You are passing the values without initializing.

    ViewController2 *view2=[[ViewController2 alloc]init];
    view2.id=name.text; 
    ViewController3 *view3=[[ViewController3 alloc]init];
    view3.id=name.text; 
    

    If you want to use object globally within your app, you can declare it in the appDelegate.

    In AppDelegate.h

     @interface AppDelegate : NSObject 
        {
             NSString *idGlobal;
        }
        @property (nonatomic, retain) NSString *idGlobal;
    

    In AppDelegate.m

    @synthesize idGlobal;
    
    In ViewController1.m:
    
    -(IBAction)butonclick:(id)sender{
    
         appDelegate.idGlobal=name.text; 
    }
    
    In ViewController2.m: and
    In ViewController3.m:
    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    id=appDelegate.idGlobal;
    

提交回复
热议问题