Reputation: 1682
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
Upvotes: 3
Views: 2941
Reputation: 9600
your
[self.view setFrame:frame];
(100,47) absolute coordinate
| |
| |
| self.view |
| |
| |
you staticTable leave zero coordinates.
staticTable = [[UITableView alloc] initWithFrame:CGRectMake(0,0,128,150) style:UITableViewStylePlain];
because
(0,0) relative coordinate for self.view.
(100,47) absolute coordinate for superView
self.view
|[ ]|
|[ ]|
|[staticTableView ]|
|[ ]|
|[ ]|
If you set the frame is equal to the image below.
staticTable = [[UITableView alloc] initWithFrame:frame style:UITableViewStylePlain];
self.view
| [ | ]
| [ | ]
| [static|TableView]
| [ | ]
| [ | ]
Upvotes: 2
Reputation: 506
the myPopover width is 128 and height is 150
so how can add table view with x cordinate with 200 it must be below 128 to show the table . frame is cordinates regarding the subView but not the totall view of the screen.
Upvotes: 1