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 ;}