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

时间:2018-03-30 09:47:45

标签: objective-c swift xcode

我正在将Objective-C代码转换为Swift。 我做了所有必需的事情,如:在Bridging-header导入“DCclass.h”等。事情工作正常,但在设置标签我面临一个问题,在谷歌上搜索这个但没有得到解决方案。感谢提前。

当前的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)")
        }
    }
}

1 个答案:

答案 0 :(得分:0)

更改方法的名称,它表示setTag swift类已存在名为UIView的现有方法。

只需将setTag更改为setCellId或您想要的内容。