0

I am developing iOS App with UITableView. I begin to develop the App with Master-Detail Application and I use StoryBoard.

I would like to insert 320px*100px margin between navigation bar and UITableView. (Height of navigation bar is 44px.)

I am writing down the following code. However margin doesn't appear.

Could you tell me how to solve this problem?

@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);

}
supermonkey
  • 631
  • 11
  • 25
  • You are setting your tableView frame to origin (0,44) size (320,100). Don't you want origin (0,144) to give you the gap? If so, try `CGRectMake(0,144,320,self.tableView.frame.size.height-100)` – pbasdf Sep 03 '14 at 08:52
  • As you indicated, the value of CGRectMake was wrong and edited to the correct value in the above code. However It remains that margin doesn't appear. – supermonkey Sep 03 '14 at 09:05
  • `@property (strong, nonatomic) IBOutlet UITableView *tableView;` is better to use `weak` for `IBOutlet` outlets, link: http://stackoverflow.com/questions/7678469/should-iboutlets-be-strong-or-weak-under-arc – Alex Peda Sep 03 '14 at 09:07
  • I change to weak, however no change. – supermonkey Sep 03 '14 at 09:11
  • Try setting `contentInset` for tableview, `[self.tableView setContentInset:UIEdgeInsetsMake(100, 0, 0, 0)];` – Akhilrajtr Sep 03 '14 at 09:28
  • Thank you very much. I can insert margin with [self.tableView setContentInset:UIEdgeInsetsMake(100, 0, 0, 0)]. – supermonkey Sep 04 '14 at 07:32

1 Answers1

2

This your line:

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

100 sets tableView height to 100 instead of margin. Try following please:

self.tableView.frame = CGRectMake(0, 44 + 100, 320, self.view.frame.size.height - 44 - 100);
Alex Peda
  • 4,210
  • 3
  • 22
  • 31