'Programming'에 해당되는 글 3건

  1. Progress Indicator 2009/09/15
  2. IPhone SDK: Application Preferences 2009/07/01
  3. Web Crawling Code in iPhone 2009/01/06

Progress Indicator

from iPhone Programming 2009/09/15 10:25
#1. Including below classes

@interface UIProgressIndicator : UIActivityIndicatorView {
}

+ (struct CGSize)size;
- (int)progressIndicatorStyle;
- (void)setProgressIndicatorStyle:(int)fp8;
- (void)setStyle:(int)fp8;
- (void)setAnimating:(BOOL)fp8;
- (void)startAnimation;
- (void)stopAnimation;
@end

@interface UIProgressHUD : UIView {
    UIProgressIndicator *_progressIndicator;
    UILabel *_progressMessage;
    UIImageView *_doneView;
    UIWindow *_parentWindow;
    struct {
        unsigned int isShowing:1;
        unsigned int isShowingText:1;
        unsigned int fixedFrame:1;
        unsigned int reserved:30;
    } _progressHUDFlags;
}

- (id)_progressIndicator;
- (id)initWithFrame:(struct CGRect)fp8;
- (void)setText:(id)fp8;
- (void)setShowsText:(BOOL)fp8;
- (void)setFontSize:(int)fp8;
- (void)drawRect:(struct CGRect)fp8;
- (void)layoutSubviews;
- (void)showInView:(id)fp8;
- (void)hide;
- (void)done;
- (void)dealloc;
@end

#2. Declaration of an instance

UIProgressHUD *progressHUD;


#3. Using method in UIViewController

[self showProgressIndicator:@"Detecting"];


#4. Showing and hiding method

- (void)showProgressIndicator:(NSString *)text {
    //[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    self.view.userInteractionEnabled = FALSE;
    if(!progressHUD) {
        CGFloat w = 160.0f, h = 120.0f;
        progressHUD = [[UIProgressHUD alloc] initWithFrame:CGRectMake((self.view.frame.size.width-w)/2, (self.view.frame.size.height-h)/2, w, h)];
        [progressHUD setText:text];
        [progressHUD showInView:self.view];
    }
}

- (void)hideProgressIndicator {
    //[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
    self.view.userInteractionEnabled = TRUE;
    if(progressHUD) {
        [progressHUD hide];
        [progressHUD release];
        progressHUD = nil;

        AudioServicesPlaySystemSound(alertSoundID);
    }
}


2009/09/15 10:25 2009/09/15 10:25

댓글을 달아 주세요

출처: http://knol.google.com/k/usman-ismail/iphone-sdk-application-preferences/34oprzanmpe7q/8#

Step 1: Create a Sample Application


I have used an application similar to the one created in the tutorial presented here (IPhone SDK Hello World).

Step 2: Create a Settings Bundle


Create a new File Command + N and then select Settings from the side menu and Settings  Bundle. The file must be named Settings.bundle to work correctly. 










This will create two new files Root.strings and Root.plist. Open the Root.plist file and you should see the following screen listing some sample settings. This is actually a graphical representation of an XML file which defines the settings and how they are displayed. (You can see the xml code by right clicking the file and selecting Open as Plain Text)




Step 3: Define Settings Schema


The Root element has three child elements (1) Title; which defines the title of this settings view and is set to the name of the application. (2) StringTable; which is not covered in this tutorial. (3) PreferenceSpecifiers which contains all the settings we wish to elicit from the user. PreferenceSpecifiers has type Array and has a child element of type Dictionary for each setting: Item 1, item2 and so forth. We can add items by selecting PreferenceSpecifiers and clicking the Grey button at the end of the row.

Each setting has several properties of type string including the common required properties; Title and Type (Note all strings are case sensitive). The title defines the label displayed beside the control used to modify the setting and type defines the type of control used. There are seven possible controls which can be selected using the Type property:


PSGroupSpecifier

This is the simplest control and has only the two properties defined described above. It is used as a separator to break-up groups of similar settings. It cannot accept any input from the user.


PSTitleValueSpecifier

This displays a "Read Only" setting it cannot accept input from the user but can be used to display settings changed elsewhere.


Key:

This is a String property which can be set to any text, the text is used as a key to map to the value that a user will enter into the control.  


DefaultValue:

Another String property which can store any text, this defines the Text that will be displayed in the specifier.



PSTextFieldSpecifier

The next type of control is the TextField, it has some additional properties which are listed below


Key:

This is a String property which can be set to any text, the text is used as a key to map to the value that a user will enter into the text field.  

DefaultValue:

Another String property which can store any text this defines the initial Text that will be entered into the TextField when it is first loaded.


IsSecure

This is a boolean property which defines if the charecters of the text field will be hidden, set to enabled for password fields.


KeyboardType

A String property which can have one of the following values: Alphabet, NumbersAndPunctuati on, NumberPad, URL, EmailAddress. This property specifies which type of keyboard to display when text field is selected

AutocapitalizationType

A String property which can have one of the following values: None, Sentences, Words, AllCharacters


AutoCorrectionType

A String property which can have one of the following values: Default, No, Yes
   

PSSliderSpecifier

This displays a slider on a bar which allows the user to select a number in a specified range. In addition to the standard Title and Type specifiers the Slider has the following properties.

Key:

This is a String property which can be set to any text, the text is used as a key to map to the value that a user will enter into the control.  

MinimumValue

A property storing a numerical value which corresponds to the slider being on the left end of the bar.

MaximumValue

A property storing a numerical value which corresponds to the slider being on the right end of the bar.

DefaultValue:

 A numerical  property which defines the original position of the slider. 



PSToggleSwitchSpecifier


Displays a toggle switch which can be either On or Off.

Key:

This is a String property which can be set to any text, the text is used as a key to map to the value that a user will enter into the control. 

TrueValue:

A boolean property which defines the value of the control of the toggle button is in the On position.

FalseValue:

A boolean property which defines the value of the control of the toggle button is in the Off position.

DefaultValue:

A boolean property which defines the position of the Toggle button the first time it is loaded.




PSMultiValueSpecifier

Multi-Value Specifier
Displays a list in a second view and allows the user to select one element from the list.

Key:

This is a String property which can be set to any text, the text is used as a key to map to the value that a user will enter into the control. 


Values:

A property of type Array which stores sub-elements of type String, each element provides a a pos sible value for the control to take. 

Titles:

A property of type array which stores sub-elements of type String, each element provides a textual representation of one of the values specified in the previous property. For example if the first element of the values array is "01" and the first element of the titles array is "January" then the user is shown January but if January is selected the value stored for the control is 01.  

DefaultValue:

Another String property that defines the initial value of the control, should be one of the elements of the Values list.

PSChildPaneSpecifier  

 

Key:

This is a String property which can be set to any text, the text is used as a key to map to the value that a user will enter into the control. 

File:

The name of another plist file without the extension.


Step 4: Retrieving Values of Settings

You can retrieve the value of a setting by using the command given below; Replace the hilighted text with the name of the setting you want to get the value of. 

NSString* settingValue = [[NSUserDefaults standardUserDefaults] stringForKey:@"<Setting Key>"]



Step 5: Loading a Child Pane


The final of the Seven Controls allows you to add a sub view. The procedure to do so is to add a new file Command + N and select Other from the menu on the right Property List from the list of fle types.

Create a child prefernces schema exactly as you created the original schema.

No in the original schema add a PSChildPaneSpecifier and add a File item to the specifier with the file name of the child view (less the extension).

Technically this should be enough but as you will see if you run your code now the child view will not load. To load your child view the child plist file has to be inside the settings bundle but I can't find a way of doing this from within XCode (after half an our of random tinkering). So just open a terminal and move the file into the bundle manually. To do this browse to the directory containing your xcode project, and find child.plist file (or whatever you named it). Use mv child.plist Settings.bundle/child.plist to move your file and then click Build and Go in XCode.

If there is some way of moving files into the bundle through XCode that you know of please leave a coment and I will update this document.

 

Concluding Note


This document is a bit raw please leave feedback in case anything is not clear, you have some suggestions or if you spot any mistakes.

You can find the source code of the example at my website;
Source Code

Appendix A: NSLogs


To see the NSLog output generated by clicking the "Load Preferences" button in the sample code click the highlighted button in shown in the figure. It will open the log output window.

 
2009/07/01 14:59 2009/07/01 14:59

댓글을 달아 주세요

그렇게 많은 시간 삽질하지 않고 알게된 Get 방식을 이용한 html 코드 크로울링 소스

- (void)applicationDidFinishLaunching:(UIApplication *)application {   
    NSString* str = [self GetGnamjaStr];
    NSData* htmlData = [str dataUsingEncoding:-2147481280];
    [webview loadData:htmlData MIMEType:@"text/plain" textEncodingName:@"EUC-KR" baseURL:nil];      
    [window makeKeyAndVisible];
}

-(NSString*)GetGnamjaStr {
    NSError *error;
    NSURLResponse *response;
    NSData *dataReply;
    NSString *stringReply;
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: [NSString stringWithFormat:@"http://사이트주소"]]];
    [request setHTTPMethod: @"GET"];
    dataReply = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    stringReply = [[NSString alloc] initWithData:dataReply encoding:-2147481280];
    return stringReply;
}

소스 보시면 알겠지만 리퀘스트하고 스트링으로 받고 웹뷰에 뿌리는 것을 알 수 있음.
인코딩 관련 부분은 한글페이지 긁는 용도로 파라미터 조정함.

스트링 처리는 기회되면 나중에~~
활용은 알아서~
2009/01/06 18:00 2009/01/06 18:00

댓글을 달아 주세요