我有一个 UIViewController
,我在其中放置了带有 2 个选项的 UISegmenetedControl
,在下面我有一个 UIView
,它作为一个容器来放置我的自定义UIView
(实际上是一个UITableView
)。在段之间切换时,我想在 2 个不同的 UITableViews 之间切换。
我的问题是 UITableView。
我用 .xib
创建了一个自定义的 UIView
类,在里面我放了一个 UITableView
并且我能够将数据填充到表中,正确看待它。
问题出在滚动上,它对垂直滚动根本没有反应!
下面是我如何创建带有表格的 UIView
。
.h
文件
@interface LeaderboardTableView : UIView
@property (strong, nonatomic) IBOutlet UIView *view;
@property (strong, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) NSDictionary *myScore;
@property (strong, nonatomic) NSArray *players;
- (id)initWithBoardType:(LeaderboardType)boardType myScore:(NSDictionary*)myScore leaderboardData:(NSArray*)data;
@end
.m文件
@implementation LeaderboardTableView
- (id)initWithBoardType:(LeaderboardType)boardType myScore:(NSDictionary*)myScore leaderboardData:(NSArray*)data {
self = [super init];
if(self) {
_players = data;
_myScore = myScore;
_boardType = boardType;
self.tableView.delegate = self;
self.tableView.dataSource = self;
}
return self;
}
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if(self) {
[self setup];
}
return self;
}
- (void)setup {
[[NSBundle mainBundle] loadNibNamed:@"LeaderboardTableView" owner:self options:nil];
[self addSubview:self.view];
}
这是我的.XIB
我做错了什么??我怀疑我的 UITableView
驻留在 UIView
中,这就是我无法滚动的原因,但我不知道如何解决这个问题。
谢谢!
最佳答案
假设您使用 initWithBoardType:myScore:leaderboardData:
来实例化您的 View ,尝试更改:
self = [super init];
通过
self = [self initWithNibName:@"LeaderboardTableView" bundle:[NSBundle mainBundle]];
在这个方法中。
但不确定它是否会解决您的滚动问题。看起来好像在您的 table 上有一个“不可见”的 View 。
请告诉我您如何显示您的 View 。
关于ios - 子类化 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19675340/