IOS Va_list,va_start,va_end

Source: Internet
Author: User
<span id="Label3"></p><p><p><br></p></p><p>-(id) initwithtitle: (nsstring *) title<br>Message: (nsstring *) Message<br>Completionblock: (void (^) (nsuinteger buttonindex, emalertview *alertview)) block<br>Cancelbuttontitle: (nsstring *) Cancelbuttontitle<br>Otherbuttontitles: (nsstring *) otherbuttontitles, ... {<br>#import <objc/runtime.h> Header Files<br>Objc_setassociatedobject requires four parameters: the source object, the keyword, the associated object, and an associated policy.<br>Objc_setassociatedobject (self, "blockcallback", [block copy], objc_association_retain_nonatomic);<br><br>If (self = [self initwithtitle:title message:message delegate:self cancelbuttontitle:nil otherbuttontitles:nil])<br>{<br>If (cancelbuttontitle) {<br>[self addbuttonwithtitle:cancelbuttontitle];<br>Self.cancelbuttonindex = [self numberofbuttons]-1;<br>}<br>ID eachobject;<br>Va_list Argumentlist;//va_list is a character pointer that can be understood as a pointer to the current parameter, which must be passed through this pointer<br>If (otherbuttontitles) {<br>[self addbuttonwithtitle:otherbuttontitles];<br>Va_start (argumentlist, otherbuttontitles);//the ArgumentList should then be initialized so that it points to the first parameter in the mutable parameter table, which is implemented by va_start, The first argument is ArgumentList itself, and the second argument is a variable that precedes the argument list, which is the parameter before "...".<br>While ((eachobject = Va_arg (argumentlist, id))) {///then is the get parameter, call va_arg, its first argument is argumentlist, the second parameter is the specified type of parameter to get, It then returns the value of the specified type, and points the position of the argumentlist to the next variable position in the argument list<br>[self addbuttonwithtitle:eachobject];<br>}<br>Va_end (argumentlist)////empty Argumentlist//after Getting all the parameters, we need to turn this argumentlist pointer off to avoid danger, by calling va_end, It causes the input parameter argumentlist to be NULL, and should form the habit of closing the pointer after the parameter table has been Obtained. To put it bluntly, is to make our program Robust. Usually Va_start and va_end are paired up.<br>}<br>}<br>Return self;<br>}<br><br><br></p><p><p>IOS Va_list,va_start,va_end</p></p></span>

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.