Skip to content

Instantly share code, notes, and snippets.

Created July 21, 2014 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/003e57bf021dbca09924 to your computer and use it in GitHub Desktop.
Save anonymous/003e57bf021dbca09924 to your computer and use it in GitHub Desktop.
//
// SOTableViewController.m
//
#import "SOTableViewController.h"
@interface SOTableViewController ()
@end
@implementation SOTableViewController
- (instancetype)init {
return [super initWithStyle:UITableViewStyleGrouped];
}
// In a UITableViewController subclass
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight |
UIViewAutoresizingFlexibleWidth;
CGFloat xMargin = 100.0f;
UIEdgeInsets contentInset = self.tableView.contentInset;
contentInset.left = xMargin;
contentInset.right = xMargin;

 CGSize contentSize = self.tableView.contentSize;
contentSize.width = contentSize.width -= xMargin * 2;
self.tableView.contentSize = contentSize;
self.tableView.contentInset = contentInset;
// Turning autolayout off doesn't appear to help
//self.tableView.translatesAutoresizingMaskIntoConstraints = NO;
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"id"];
cell.textLabel.text = [NSString stringWithFormat:@"Cell %d", indexPath.row];
return cell;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment