In the second view controller, create an NSString property, call it something like self.userName. In the first view controller, use the prepareForSegue method and instantiate an object of the secondary view controller ie.Hi all,
I have two view controllers
1) with a log in box, username and password
and 2) with a label
how do i get the label to say Welcome, Username
replace username with the actual username obviously
Thanks
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.destinationViewController isKindOfClass:[SecondaryViewController class]]) {
SecondaryViewController *viewController = segue.destinationViewController;
viewController.userName = self.userNameTextField.text;
}
}
self.welcomeLabel.text = [NSString stringWithFormat:@"Welcome, %@", userNameString];
is there a way so if the user registers a username eg bob.
it comes out as Welcome, Bob
as in change the first letter to a capital letter?
Read the
String Programming Guide
https://developer.apple.com/library...troStrings.html#//apple_ref/doc/uid/10000035i
Everyone has to read this.
There is a way to do it, but as chown said it is not advisable. For questions like this, the developer documentation is best, and when clarification is needed, so is stackoverflow (though keep in mind some code from stackoverflow is old, meant for Cocoa on OS X, or outright wrong/inefficient, so be careful). As a general rule for myself, I never use code from a place like stack overflow unless I take it apart piece by piece and understand precisely how it works, then I write it myself (never just a straight copy and paste) and write dlwn every detail in my notes to, make sure I am learning from the experience.is there a way so if the user registers a username eg bob.
it comes out as Welcome, Bob
as in change the first letter to a capital letter?
NSString *userName = (wherever you get the username from...);
NSString *capitalizedUsername = [userName capitalizedString];