The OS X Developer Library shows how to create a method that takes a variable number of arguments in the following technical article: http://developer.apple.com/library/mac/#qa/qa1405/_index.html .
I am trying to find out if subclasses of an existing implementation of a method are possible that accepts args and calls the implementation of a superclass.
Using the UIActionSheet as an example, look at the code below. The call to the supWrite method initWithTitle passes only the first "otherButtonTitle". I do not know how to pass the remaining lines contained in the variable argument list.
// MyActionSheet.m - (id)initWithTitle:(NSString *)title delegate:(id < UIActionSheetDelegate >)delegate cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ... { // this calls the superclass initWithTitle: method but does not // pass NIL terminated list of strings self = [super initWithTitle:title delegate:delegate cancelButtonTitle:cancelButtonTitle destructiveButtonTitle:destructiveButtonTitle otherButtonTitles:otherButtonTitles, nil]; if (self) { // custom initialization } return self; }
I can get the arguments using va_list, va_start, va_end, but I donβt know how to pass them to the superclass method.
In case someone is tempted to tell me that I can do it differently (for example, do not go through the args variables, but use va_list, va_start, va_end to create an array of strings and call addButtonWithTitle: several times, I know that I can do this. As an example, I used UIActionSheet. There are other cases where the ability to subclass a method with args variables would be useful, and I would like to know how to do what I asked if this is possible.
thanks!
source share