0

hi i am new to iphone development.

I'm trying with sample where I need to copy a string from the textfield of viewController and display it on the next view with a Label.

On the first view there is button bellow the textfield.1 I am not able to fix some issues showing BAD ACESS can anyone help me in solving this. Let me know what i'm doing Wrong.

Thank you.

//copystring.h

@interface CopystringViewController : UIViewController{

    UITextField *myTextField;
    NSString *somestring;
}

@property(nonatomic,retain)IBOutlet UITextField *myTextfield;

@property(nonatomic,retain)NSString *somestring;

-(IBAction)next:(id)sender;

//.m file

@synthesize myTextfield,somestring;


-(IBAction)next:(id)sender;
{

    NextView * next = [[NextView alloc] initWithNewString: myTextField.text];

    [self.navigationController presentModalViewController: next animated: YES];

}

NextView.h


@interface NextView : UIViewController{

    UILabel  *string2;

}
@property(nonatomic,retain)IBOutlet UILabel *string2;

- (id)initWithNewString:(NSString*)someString;


//.m file

@synthesize string2;


 -(id)initWithNewString:(NSString*)someString {

    string2 = someString;
 return self;

}

7 Answers 7

4

Just replace method.it may run.

-(IBAction)next:(id)sender; {

    NextView * next = [[NextView alloc] initWithNibName:@"NextView" bundle:nil];
    next.string2=myTextField.text;
    [self.navigationController presentModalViewController:next animated: YES];

}
Sign up to request clarification or add additional context in comments.

2 Comments

@jatin patel i did above changes but i am not able to display the text entered in a textfield of first view to next view
@crazy2431 , Check it whether you are able to display text in same view. if no then bind your object with text field..
1

hey string2 is a label so try string2.text = somestring;

 -(id)initWithNewString:(NSString*)someString {

string2.text = someString;

 return self;

 }

Comments

1

It looks like the problem is that you're assigning an NSString (someString) to a UILabel (string2).

AppleVijay's answer should do the trick.

If you don't like dot-notation in ObjC you can also write it like this:

[string2 setText:someString]

Comments

1

U can declare ur somestring in to the delagate h/m file that way it wil be the global string. u can use it with appdaligateobj.stringname.

U dont evn need init u can directly add to viewdidload of next view.

string2.text = AppDalegateobj.stringName.

1 Comment

can u tel me with the code as i am new to development i am not getting it
1

Delegation is the usual way to move data around like this. I wrote a very simple example project to show this in action.

Comments

0

You need init you view and retain you string:

-(id)initWithNewString:(NSString*)someString {
  self = [super init];

  if (self) {
    string2.text = someString;
  }
 return self;

}

Comments

0

/

/AppDelegate.h

NSString *String1;

@property (nonatomic, retain) NSString * String1;

//AppDelegate.m
@synthesize String1

//ViewController1.h

AppDelegate * objAppDelegate;
UILable *lblstring;


@property (nonatomic, retain) UILable *lblstring;

//ViewController1.m
@synthesize lblstring

//On View Did Load.
objAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
lblstring.text  = objAppDelegate.String1;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.