【问题标题】:Insert margin between navigation bar and UITableView在导航栏和 UITableView 之间插入边距
【发布时间】:2014-09-03 08:45:01
【问题描述】:

我正在使用 UITableView 开发 iOS 应用程序。我开始使用 Master-Detail Application 开发应用程序,并使用 StoryBoard。

我想在导航栏和 UITableView 之间插入 320px*100px 的边距。 (导航栏高度为44px。)

我正在写下以下代码。但是边距没有出现。

你能告诉我如何解决这个问题吗?

@interface MasterViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (strong, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation MasterViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.frame = CGRectMake(0, 144, 320, self.view.frame.size.height);

}

【问题讨论】:

  • 您将 tableView 框架设置为原点 (0,44) 大小 (320,100)。难道你不想 origin (0,144) 给你差距吗?如果是这样,请尝试CGRectMake(0,144,320,self.tableView.frame.size.height-100)
  • 如您所指,CGRectMake 的值是错误的,并在上面的代码中编辑为正确的值。但是仍然没有出现边距。
  • @property (strong, nonatomic) IBOutlet UITableView *tableView; 最好使用weak 用于IBOutlet 网点,链接:stackoverflow.com/questions/7678469/…
  • 我变弱了,但没有变化。
  • 尝试为tableview设置contentInset[self.tableView setContentInset:UIEdgeInsetsMake(100, 0, 0, 0)];

标签: ios objective-c uitableview uinavigationbar


【解决方案1】:

这是你的线路:

self.tableView.frame = CGRectMake(0, 44, 320, 100);

100 将 tableView 高度设置为 100 而不是边距。请尝试以下操作:

self.tableView.frame = CGRectMake(0, 44 + 100, 320, self.view.frame.size.height - 44 - 100);

【讨论】:

  • 谢谢。但是边距没有出现。
  • 其他方法不改tableView.frame吗?
  • 不,我不会改变其他方法。
  • 请尝试更改相关视图的背景颜色。例如,self.view.backgroundColor = [UIColor blueColor];self.tableView.backgroundColor = [UIColor redColor];。只是为了更好地了解它的外观
  • 截图非常感谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-05
  • 2014-11-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多