Iphone 是否可以使用类似UITableViewCellStyle的枚举作为方法的参数?
我想要一个枚举作为我函数的参数。这样行吗Iphone 是否可以使用类似UITableViewCellStyle的枚举作为方法的参数?,iphone,objective-c,cocoa-touch,enums,Iphone,Objective C,Cocoa Touch,Enums,我想要一个枚举作为我函数的参数。这样行吗 (UIFont*) myMethodName:(UITableViewCellStyle) cellStyle { //... if (cellStyle == UITableViewCellStyleValue2) // ... } 然后我会这样调用这个方法 UIFont *resultFont = [self myMethodName:UITableViewCellStyleSubtitle]; 仅允许以下参数:
(UIFont*) myMethodName:(UITableViewCellStyle) cellStyle {
//...
if (cellStyle == UITableViewCellStyleValue2)
// ...
}
然后我会这样调用这个方法
UIFont *resultFont = [self myMethodName:UITableViewCellStyleSubtitle];
仅允许以下参数:
UITableViewCellStyleDefault,
UITableViewCellStyleValue1,
UITableViewCellStyleValue2,
UITableViewCellStyleSubtitle
可能吗?当然可以:
typedef enum _MyType {
type_a = -1,
type_b = 0,
type_c = 1,
} MyType;
...
- (void) someMethod:(MyType)type {
if (type == type_a) ...
}
当然可以:
是的,有可能
(这似乎是一个不必要的简短回答,但我想不出还有什么可以补充!)是的,这是可能的
(这似乎是一个不必要的简短回答,但我想不出还有什么可以补充的!)- 这样行吗?→ 对
- 仅允许以下参数:→ 不,不可能将输入仅限于这些值,即
仍将编译(假设您不使用Objective-C++)UIFont *resultFont = [self myMethodName:12345];
- 这样行吗?→ 对
- 仅允许以下参数:→ 不,不可能将输入仅限于这些值,即
仍将编译(假设您不使用Objective-C++)UIFont *resultFont = [self myMethodName:12345];