开发者社区 问答 正文

tableView占满整个屏幕

在app中需要用到一个小 tableView,我设置了尺寸,但是运行之后 tableview 占了整个屏幕。

 -(void)viewDidLoad{
 UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0.0, 0.0, 20.0, 60.0) style:UITableViewStylePlain];
   self.view = tableView;
 }
   - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyCellIdentifier = @"MyCellIdentifier";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:MyCellIdentifier];
if(cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyCellIdentifier];
}
return cell;
   }
  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 5;
  }

展开
收起
爵霸 2016-03-24 09:29:25 2226 分享 版权
1 条回答
写回答
取消 提交回答
  • self.view = tableView;
    改成
    [self.view addSubview:tableView];

    2019-07-17 19:11:54
    赞同 展开评论
问答地址: