Write the interface architecture of the iPhone wap browser by yourself (iphone development-advanced)

Source: Internet
Author: User

Author: Sun Dongfeng (source)

In my previous article "manually write the BSD Socket engine of iPhone wap browser", the tags on the wml page have been successfully parsed, if you are careful, you may see Chinese characters in the tag display as garbled, this is because the default Chinese encoding format on the iPhone is UTF-8, And the request through BSD Socket is ASCII code, so you need to convert to UTF-8 format, as shown below:

 

[[NSString alloc] initWithBytes: aChild-> Value () length: strlen (aChild-> Value () encoding: NSUTF8StringEncoding]

 

After transcoding, the printed content displayed on the screen is as follows:

 

Parse xml succeed

AChild value = STATUS OK

AChild value = card

TiXmlNode: ELEMENT name = title, attr value = Baidu, you will know

AChild value = p

AChild value = img

TiXmlNode: ELEMENT name = src, attr value =/r/wise/wapsearchindex/logoindexsmall.gif

TiXmlNode: ELEMENT name = alt, attr value = Baidu Homepage

AChild value = br

AChild value = input

TiXmlNode: ELEMENT name = name, attr value = word

TiXmlNode: ELEMENT name = emptyok, attr value = true

AChild value = br

AChild value = anchor

AChild value = search Web Page

TiXmlNode: TEXT Value = search Web Page

 

The next task is to render the parsed tags and display them on the interface. In this article, I will focus on building a scalable and robust interface architecture.

 

I have always admired MVC in the interface architecture of all platforms. The focus of MVC is to separate the interface display and data processing to provide a scalable interface architecture platform. Based on this idea, the author builds the following Architecture diagram:

 

Figure 1. Tag Interface Architecture

 

After the Xml module processes the xml data and extracts the tag, it is handed over to CXmlControl for processing. CXmlControl acts as a Control here. It is responsible for processing the tag) then generate the corresponding message to display on the interface.

 

CXmlControl inherits from the UIView class and is responsible for displaying the interface and responding to users' key messages. The specific logic processing is performed in the CXmlControlImpl class, the CXmlControlImpl class is used to manage the generated tag and the Layout (Layout) interface of the tag, as shown below:

 

 

 

@ Class CXmlControlImpl;

@ Interface CXmlControl: UIView {

@ Public

CXmlControlImpl * iImpl;

}

 

-(Void) addElements :( CXmlElementImpl *) iElemntAdded;

 

-(CXmlElement *) InsertContent :( CXmlElement *) aTarget aPosition :( NSInteger) aPosition aSource :( const NSString *) aSource aFlags :( NSInteger) aFlags;

-(CXmlElement *) AppendContent :( const NSString *) aSource aFlags :( NSInteger) aFlags;

-(Void) Refresh;

-(Void) RefreshAndDraw;

-(Void) ClearContent;

-(Void) RemoveElement :( CXmlElement *) aElement;

-(CXmlElement *) Element :( const NSString *) aId aIndex :( NSInteger) aIndex;

-(CXmlElement *) ElementByTag :( const NSString *) aTagName aIndex :( NSInteger) aIndex;

-(CXmlElement *) FocusedElement;

-(Void) SetFocusTo :( CXmlElement *) aElement;

-(Void) ScrollToView :( CXmlElement *) aElement;

-(CXmlElement *) Body;

-(Void) SetEventObserver :( id <MXmlCtlEventObserver>) aObserver;

-(CXmlElementImpl *) Impl;

-(CGContextRef) SystemGc;

 

-(Void) Draw :( const CGRect) aRect;

 

-(CWritableBitmap *) OffScreenBitmap;

-(Void) SetOffScreenBitmap :( CWritableBitmap *) aBitmap;

-(Void) DrawOffscreen;

 

-(Void) touchesBegan :( NSSet *) touches withEvent :( UIEvent *) event;

-(Void) touchesMoved :( NSSet *) touches withEvent :( UIEvent *) event;

-(Void) touchesEnded :( NSSet *) touches withEvent :( UIEvent *) event;

@ End

 

The base class of the Tag class is CXmlElement, which abstracts the basic attributes and operations of the tag) classes such as CXmlTextElement and CXmlImgElement maintain a global layout class CHcMeasureStatus. Each tag class is responsible for its own layout and painting operations, after the layout and drawing operations are completed, the status and Properties of CHcMearuseStatus are changed and passed to the CXmlControl class.

 

In the next article, I will try to parse and render common Text labels and try to finish them before New Year's Day :)

 

The series of articles and codes in this tutorial will be included in my new book "hands-on iPhone development". Therefore, any form of business plagiarism will be held accountable.

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.