I have a view controller that has a tableView in it. When I set the frame of it’s tableView, it appears on the screen at a different place then the frame that I gave it. For example, giving it an X coord of 200 with a width of 128 puts the whole thing off the screen.
Here is where I instantiate the view controller:
myPopover = [[PopupVC alloc] initWithFrame:CGRectMake(100, 47, 128, 150)];
And the init code for the view controller:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (id)initWithFrame:(CGRect)_frame
{
self = [self initWithNibName:nil bundle:nil];
if (self)
{
frame = _frame;
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view setFrame:frame];
staticTable = [[UITableView alloc] initWithFrame:frame style:UITableViewStylePlain];
[self.view addSubview:staticTable];
}
Does anybody know why this is happening? When logging the frame, it says exactly what I entered, but this is obviously not the frame that is being put on the view. As another test, I made a view of the exact same dimensions which clearly showed that they are in different places. Very weird, any help is appreciated.
Thanks
your
[self.view setFrame:frame];
(100,47) absolute coordinate
you staticTable leave zero coordinates.
because
(0,0) relative coordinate for self.view.
(100,47) absolute coordinate for superView
If you set the frame is equal to the image below.