使用Objective-C选择器的方法'setTag' 'setTag:'与具有相同Objective-C选择器的超类'UIView' 'tag'的setter冲突



我正在将我的Objective-C代码转换为Swift。我已经完成了所有必需的事情:在桥接头脑中导入了" dcclass.h"等。事情正常工作,但是在设置标签时,我面临问题,在Google上搜索了此问题,但没有找到解决方案。

当前的Objective-C代码:

.h文件:

#import <UIKit/UIKit.h>
#import “DCclass.h”
@interface LPFPickerCell : UITableViewCell <UITableViewDelegate, UIPickerViewDelegate,UIPickerViewDataSource>
- (void)setDelegate:(id) delegate;
- (void)setMyMutableArray:(NSMutableArray *) mutArray;
- (void)setSelectedData:(NSString *) selectedString
@end

.m文件:

#import “DCclass.h”
@interface LPFPickerCell ()
@property (nonatomic) NSMutableArray *myMutableArray;
@end
@implementation LPFPickerCell
- (void)setTag:(NSInteger)tag
{
    self.m_Tag = tag;
}
- (void)setSelectedData:(NSString *) selectedString
{    
    int i = 0;
    for (DCclass *dc in self.myMutableArray)
    {
        NSLog(@"DCclass.empName = %@",dc.empName);
    }
}
@end

转换后的Swift代码:

class LPFPickerCell {
    var myMutableArray = [AnyHashable]()
    var m_Tag: Int = 0
    func setTag(_ tag: Int) {   /// This line is showing error same as Question post title described above.
        m_Tag = tag
    }
    func setSelectedData(_ selectedString: String?) {
        let i: Int = 0
        for dc: DCclass in myMutableArray {
        print("DCclass.empName = (dc.empName)")
        }
    }
}

更改方法的名称,它说具有UIView Swift类名称setTag的现有方法。

只需将setTag更改为setCellId或您想要的东西。

最新更新