【发布时间】:2023-04-03 19:51:01
【问题描述】:
我在我的类中创建了一个 UITableView 属性,并为它创建了 getter 方法,如下所示:
@interface SideViewController : UIViewController <UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong) UITableView *table;
@end
@implementation SideViewController
@synthesize selectedIndex;
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor redColor];
}
- (UITableView*)table {
if (!_table) {
CGRect tableFrame = CGRectMake(0,150,230, self.view.frame.size.height-150);
_table = [[UITableView alloc]initWithFrame:tableFrame style:UITableViewStylePlain];
_table.scrollEnabled = NO;
_table.delegate = self;
_table.dataSource = self;
_table.showsVerticalScrollIndicator = YES;
_table.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
[_table setBackgroundColor:[UIColor clearColor]];
_table.separatorStyle = UITableViewCellSeparatorStyleNone;
}
return _table;
}
当我打电话给self.table 拿到我的桌子时,我想用 swift 编写这段代码,但我很困惑!!!
请指导我。
这是我的快速代码:
import UIKit
class SideViewController: UIViewController,UITableViewDelegate {
let table:UITableView = UITableView()
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.redColor()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
【问题讨论】:
标签: ios objective-c uitableview swift