我在ObjC 这个代码,我想还是试图将其转换为SWIFTSwift - 枚举button.tag?
typedef NS_ENUM(NSInteger, BB3Photo) {
kirkenType = 10 ,
festenType = 20 ,
praestType = 30
};
@property (nonatomic, assign) BB3Photo selectedPhotoType;
- (IBAction)changeImage:(id)sender {
if ([sender isKindOfClass:[UIButton class]]) {
UIButton *button = sender;
_selectedPhotoType = button.tag;
}
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Vælg Billed"
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:@"Vælg fra Biblioteket", @"Vælg Kamera", nil];
sheet.actionSheetStyle = UIActionSheetStyleDefault;
[sheet showInView:[self.view window]];
}
这里是我已经用它制成的
enum BBPhoto1: Int {
case kommunen = 10
case sagsbehandler = 20
case festen = 30
}
var selectedPhoto = BBPhoto1.self
@IBAction func changeImage(sender: AnyObject){
if sender .isKindOfClass(UIButton){
let button: UIButton = sender as UIButton
selectedPHoto = (sender as UIButton).tag as BBPhoto1 // doesent work "cannot assign that result as expression"
selectedPHoto = button.tag // doesnt work either "cannot assign that result as expression"
self.selectedPhoto = BBPhoto1.fromRaw((sender as UIButton).tag) // nope "cannot convert the expressions type() to type UIButton"
}
}
我希望能够有一个开关语句与按钮标签相同的功能,但在代码不同
为什么'@IBAction func changeImage(sender:UIButton){...'directly?你是否期待其他类型的_senders_? – holex 2018-02-13 09:05:09