Can anyone explain to me how to pass multiple values into a parameter or variable in objective-c as below and how to handle it inside method:
view.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin
| UIViewAutoresizingFlexibleT开发者_运维问答opMargin;
What you're seeing is a simple disjunction between integers, the UIView autoresizing mask parameters are just typedef'ed enum values. You can create these on your own:
typedef enum {
IceCreamChocolateSyrup = 1 << 1,
IceCreamCaramelSyrup = 1 << 2,
IceCreamMapleSyrup = 1 << 3,
// etc. up to 31 flavors
} IceCreamSyrups;
Then you define a method that accepts them as parameter:
- (void)addIceCreamSyrups:(IceCreamSyrups)syrups {
if (syrups & IceCreamChocolateSyrup)
[self addChocolateSyrup];
if (syrups & IceCreamCaramelSyrup)
[self addCaramelSyrup];
if (syrups & IceCreamMapleSyrup)
[self addMapleSyrup];
}
And call this method as follows:
[self addIceCreamSyrups:(IceCreamChocolateSyrup | IceCreamMapleSyrup)];
精彩评论