-1
我用Swift编写了一个项目(在项目中使用此项目之前编写)。我在程序中遇到了一个问题:使用swift将tableView添加到自定义视图
自定义视图有一个按钮,点击按钮会弹出一个列表,点击其中一个单元格列表,按钮的内容就会变成单元格的内容。据了解,该代码是用Objective C的
@property (nonatomic, weak) UITableView *tableView;
@property (weak, nonatomic) IBOutlet UIButton *cityBtn;
- (UITableView *)tableView {
if (_tableView == nil) {
UITableView *tableView = [[UITableView alloc] init];
tableView.dataSource = self;
tableView.delegate = self;
tableView.backgroundColor = [UIColor blackColor];
tableView.alpha = 0.9;
tableView.x = self.cityBtn.x;
tableView.y = CGRectGetMaxY(self.cityBtn.frame);
tableView.width = self.cityBtn.width;
tableView.heigth = 0;
tableView.layer.cornerRadius = 10;
[self addSubview:tableView];
_tableView = tableView;
}
return _tableView;
}
请问这个代码是如何转换成斯威夫特
我原本是这样写的,但执行后没有显示它 – RaymondWoo
嗨,我已经实现了代码:beetxt.com/2F3。如果有任何错误,请提出查询。谢谢。 –