IOS 5 Programming (2)-Use of uiswitch, uisegmentedcontrol, and uiwebview controls

Source: Internet
Author: User

In this example, the iOS app demonstrates the use of the following controls to obtain the web content of a specific URL from a third-party website and display it in the uiwebview control.

    • Uiswitch)
    • Uisegmentedcontrol)
    • Web View)

The following figure shows how the iPhone app runs in this example:

 

The following is the main method for iOS apps to obtain the web content of a specific URL.Code:

-(Ibaction) getflower :(ID) Sender {
Nsurl * imageurl;
Nsurl * detailurl;
Nsstring * imageurlstring;
Nsstring * detailurlstring;
Nsstring * color;
IntSessionid;

Color = [self. colorchoice titleforsegmentatindex: Self. colorchoice. selectedsegmentindex];
Sessionid = random () %50000;

Imageurlstring = [[nsstring alloc] initwithformat:
@"Http://www.floraphotographs.com/showrandomios.php? Color = % @ & session = % d", [Diccolor objectforkey: Color], sessionid];
Detailurlstring = [[nsstring alloc] initwithformat:
@"Http://www.floraphotographs.com/detailios.php? Session = % d", Sessionid];

Imageurl = [[nsurl alloc] initwithstring: imageurlstring];
Detailurl = [[nsurl alloc] initwithstring: detailurlstring];

[Self. flowerview loadrequest: [nsurlrequest requestwithurl: imageurl];
[Self. flowerdetailview loadrequest: [nsurlrequest requestwithurl: detailurl];

Self. flowerdetailview. backgroundcolor = [uicolor clearcolor];
}

 

The above code briefly explains the basic process as follows:

    1. First, create an nsstring, that is, the web URL;
    2. Create an nsurl instance based on the web URL and call the initwithstring method;
    3. Create an nsurlrequest object that can be passed to the Web View for loading and call the requestwithurl method;
    4. Finally, the request is passed to the loadrequest method of the Web View. This method takes over the work, processes the loading process, and displays the webpage content in the Web View.

Download the source code of this example app.

IOS 5 Programming (1)-Use of image views, slide blocks, and step controls

IOS 5 Programming (3)-create mode switching, multi-scenario and switching)

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.