Variable parameters in iOS Processing Method

Source: Internet
Author: User

Variable parameters in iOS Processing Method
# Variable parameters in iOS Processing Methods

I recently wroteCustom dialog boxTo simulate the implementation of the system's UIAlertView.Variable parametersI encountered a small problem, So Google wrote down the method to solve the problem and recorded it for future use.

Code Implementation
-(Instancetype) initWithTitle :( NSString *) title message :( NSString *) message delegate :( id) delegate cancelButtonTitle :( NSString *) cancelButtonTitle otherButtonTitles :( NSString *) conflict ,... {if (self = [super init]) {self. title = title; self. delegate = delegate; self. frame = CYScreen. bounds; // get the variable parameter value if (! [Self isBlankString: cancelButtonTitle]) {[self. buttonTitles addObject: cancelButtonTitle];} NSString * str; va_list list; if (otherButtonTitles) {// 1. get the CYLog (% @, otherButtonTitles) of the first parameter; [self. buttonTitles addObject: otherButtonTitles]; // 2. starting from 2nd parameters, obtain the values of all parameters va_start (list, otherButtonTitles); while (str = va_arg (list, NSString *))) {CYLog (@ % @, str); [self. buttonTitles addObject: str];} va_end (list);} CYLog (% @, self. buttonTitles);} return self ;}
Method call
-(IBAction) showDialog {CYAlertView * alert = [[CYAlertView alloc] initWithTitle: @ My prompt message: @ message body delegate: self cancelButtonTitle: @ cancel otherButtonTitles: @ OK, @ XXX, @ YYY, nil]; alert. containerView = [self createDemoView]; [alert show];}
Print results
15:54:26. 422 CYCustomAlertView [358: 42937] OK 15:54:26. 424 CYCustomAlertView [358: 42937] XXX2015-07-06 15:54:26. 424 CYCustomAlertView [358: 42937] YYY2015-07-06 15:54:26. 425 CYCustomAlertView [358: 42937] (cancel, OK, XXX, YYY ,)

 

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.