IOS Study Notes (3)

Source: Internet
Author: User

The core of the Controller and View Model application is responsible for computing and creating a virtual world, which can exist without the View and Controller. (An application without an interface) Controller usually refers to View controller in Xcode. You can think of it as a bridge between Model and View. View is a window for users to communicate with the program. In most cases, View is used to display the data provided by the Model. In addition, View is also responsible for processing interaction with users. Users interact with applications through views, while controllers capture interaction messages and send them to models. When you use UIAlertView, the following message is displayed: UIAlertView * alertView = [[UIAlertView alloc] initWithTitle: @ "Title" Message: @ "message" delegate: nil cancelbuttontitles: @ "OK", nil]; [alertView show]; UIAlertView provides a property tyledef enum {UIAlertViewStyleDefault = 0, // default style: UIAlertViewStyleSecureTextInput, // In this style, the prompt view contains a secure and encrypted text field. UIAlertViewStylePlainTextInput, // in this style, the prompt view displays a visible text field. In general, this style is used to require users to enter some information, such as phone numbers. UIAlertViewStyleLoginAndPasswordInput // in this style, the prompt view displays two text columns, one is the visible user name column, and the other is the encrypted password column .} UIAlertViewStyle; if you want to receive user operation notifications from the prompt view, you must create a delegate object that complies with the UIAlertViewDelegate protocol. AlertView: clickedButtonAtIndex can be used to obtain the button that the user presses on the prompt view. -(NSString *) yesButtonTitle {return @ "Yes";}-(NSString *) noButtonTitle {return @ "No";} [[UIAlertView alloc] initWithTitle: @ "Title" message: @ "Message" delegate: nil cancelButtonTitle: [self noButtonTitle] otherButtonTitles: [self yesButtonTitle], nil];-(void) alertView :( UIAlertView *) alertView clickedButtonAtIndex :( NSInteger) buttonIndex {NSString * buttonTitle = [alertView buttonTItleAtIndex: buttonIndex]; If ([buttonTitle isEqualToString: [self yesButtonTitle]) {YES;} else if ([buttonTitle isEqualToString: [self noButtonTitle]) {NO ;}} use UISwitch to create and use the switch definition and initialize @ property (nonamotic, strong) UISwitch * muSwitch; self. view. backgroundColor = [UIColor whiteColor]; self. mySwitch = [[UISwitch alloc] initWithFrame: CGRectMake (100,100,)]; self. view addSubview: self. mySwitch]; [self. mySwitch setOn: YES]; // preset status judgment switch if ([Self. mySwitch isOn]) {NSLog (@ "On");} else {NSLog (@ "Off");} If you want to receive a message notification when the switch control is enabled or disabled, the target must be added to the class. [Self. mySwitch addTatget: self action: @ selector (switchIsChanged :) forControlEvents: UIControlEventValueChanged];-(void) switchIsChanged :( UISwitch *) paramSender {if ([paramSender isOn]) {ON ;} else {OFF ;}} uses UIPickerView to bind data @ interface PickerView: UIViewController <UIPickerViewDataSource, metadata> @ property (nonamotic, strong) UIPickerView * myPicker; @ synthesize myPicker; self. view. backgeoundColor = [UIColor whiteColor]; self. myPicker = [[UIPickerView alloc] init]; self. myPicker. dataSource = self; self. myPicker. delegate = self; self. myPicker. showsSelectionIndicator = YES; // horizontal shadow effect self. myPicker. center = self. view. center; self. view addSubview: self. myPicker];-(NSInteger) numberOfComponentsInPickerView :( UIPickerView *) pickerView {// number of components NSInteger result = 0; if ([pickerView isEqual: self. myPicker]) {result = 1;} return result;}-(NSInteger) pickerView :( UIPickerView *) pickerView numberOfRowsInComponent :( NSInteger) component {// how many options does a component have NSInteger result = 0; if ([pickerView isEqual: self. myPicker]) {result = 10;} return result;}-(NSString *) pickerView :( UIPickerView *) pickerView titleForRow :( NSInteger) row forComponent :( NSInteger) component {NSString * result = nil; if ([pickerView isEqual: self. myPicker]) {result = [NSString stringWithFormat: @ "Row % id", (long) row + 1];} return result ;}// method of monitoring selectedRowInComponent: // value reset reloadCompoment: Use UIDatePicker to bind the date and time @ interface DatePicker: Counter @ property (nonamotic, strong) UIDatePicker * myDatePicker; @ end @ synthesize myDatePicker; self. myDatePicker. backgroundColor = [UIColor whiteColor]; self. myDatePicker = [[UIDatePicker alloc] init]; self. myDatePicker. center = self. view. center; [self. view addSubview: self. myDatePicker]; [self. myDatePicker addTarget: self action: @ selecter (datePickerDateChanged :) forControlEvents: UIControlEventValueChanged]; Display Effect: // you can set the relevant parameter typedef enum {UIDatePickerModeTime, expires, expires, UIDatePickerModeCountDownTimer,} UIDatePickerMode; // obtain the current time value-(void) datePickerDateChanged :( UIDatePicker *) paramDatePicker {if ([paramDatePicker isEqual: self. myDatePicker]) {NSLog (@ "Selected date = % @", paramDatePicker. date) ;}} // select the time range (2013.1 -- 2014.1) NSDate * oneYearFromToday = [todayDate Duration: oneYearTime]; NSDate * twoYearFromToday = [todayDate Duration: 2 * oneYearTime]; self. myDatePicker. minimumDate = oneYearFromToday; self. myDatePicker. maximumDate = twoYearsFromToday; // stopwatch function-(void) viewDidLoad {[super viewDidLoad]; self. view. backgroundColor = [UIColor whiteColor]; self. myDatePicker = [[UIDatePicker alloc] init]; self. myDatePicker. datePickerMode = UIDatePickerModeCountDownTimer; [self. view addSubview: self. myDatePicker]; NSTimeInterval townMinutes = 2*60; [self. myDatePicker setCountDownDuration: twoMinutes];}

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.