A number of classes in Cocoa have methods that take variable numbers of arguments. In most cases, these classes will also have an equivalent method that takes a va_list. It's only possible to do what you're suggesting if the class you're using provides one of those methods.
For instance, +NSString stringWithFormat:... takes a variable number of arguments. Cocoa provides -NSString initWithFormat:arguments: where the arguments parameter is a va_list. This allows you to do the following.
A number of classes in Cocoa have methods that take variable numbers of arguments. In most cases, these classes will also have an equivalent method that takes a va_list. It's only possible to do what you're suggesting if the class you're using provides one of those methods.
For instance, +NSString stringWithFormat:... takes a variable number of arguments. Cocoa provides -NSString initWithFormat:arguments: where the arguments parameter is a va_list. This allows you to do the following: - (void)setContentsWithFormat:(NSString *)formatString, ... { contents autorelease; va_list args; va_start(args, formatString); contents = NSString alloc initWithFormat:formatString arguments:args; va_end(args); } The va_list parameter allows us to pass our own variable argument list to the Cocoa method so that the Cocoa method can handle the arguments.
However, since UIAlertView doesn't provide a va_list API, the cleanest way is probably to make repeated calls to addButtonWithTitle.
You can't. Objective-C's variable arguments support is effectively that of C, and as you may already know there is no (portable) way to correctly set up the stack to call to a variadic function. If the designer of the superclass was on the ball, there will be a parallel function that takes a va_list or NSArray argument that you can call instead.
If not, you're usually out of luck. In this particular case, you could call the superclass's constructor with nil for all the buttons, and then use addButtonWithTitle:, cancelButtonIndex, and so on to setup the buttons "manually".
If you can't do it the proper way, you can always do this: id arg1 = ...; // nil or 1st arg id arg2 = ...; // nil or 2nd arg id arg3 = ...; // nil or 3rd arg id arg4 = ...; // nil or 4th arg // etc. Self = super initWithTitle:title delegate:delegate cancelButtonTitle:cancelButtonTitle destructiveButtonTitle:destructiveButtonTitle otherButtonTitles:arg1,arg2,arg3,arg4,/*etc*/ nil; ugly as hell, but it will work.
You would have to know exactly how many args are passed in with this approach. – raidfive Apr 1 at 0:30 Sure? I thought the point of a nil terminated list was that it terminates on the nil.
Also I see no problems in a quick test, supplying a UIAlertView this as the last argument: @"OK",nil,nil,nil,nil,nil,nil – mvds Apr 1 at 0:33 agreed, this will work but too ugly for me to consider unless I was desperate. And it does have the limitation that it will only support the max number of args you hard code as arg vars. – XJones Apr 1 at 3:51.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.