IOS learning-2. source code is displayed on the web site, and ios learning-2 source code

Source: Internet
Author: User

IOS learning-2. source code is displayed on the web site, and ios learning-2 source code

Enter the URL, work out the source code, and display the label

This is displayed on the second page. The attribute is used to pass the value.

On interface a, drag A textfield and A button from the storyboard.

Button method in. m

// Click method-(IBAction) Click :( id) sender {// prefix NSString * str1 = @ "http ://"; // Add the prefix NSString * str2 = [str1 stringByAppendingString: _ field. text]; // decodes NSString * str = [NSString stringWithContentsOfURL: [NSURL URLWithString: str2] encoding: NSUTF8StringEncoding error: nil]; NSLog (@ "% @", str ); secondController * secondView = [[SecondController alloc] init]; // assign the obtained string to the attribute secondView of interface B. string = str; // jump, I use navgation to skip [self. navigationController pushViewController: secondView animated: YES];}

Interface B defines a string for receiving

@property(nonatomic,copy)NSString *string;

. M

-(Void) viewDidLoad {[super viewDidLoad]; self. view. backgroundColor = [UIColor whiteColor]; UILabel * label = [[UILabel alloc] initWithFrame: CGRectMake (0, 64, self. view. bounds. size. width, self. view. frame. size. height)]; [self. view addSubview: label]; label. numberOfLines = 0; label. lineBreakMode = NSLineBreakByTruncatingTail; // The received value is assigned to the label. text = _ string ;}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.