UITableView Frame setting not working correctly
I have a view controller that has a tableView. When I frame its tableView, it appears on the screen elsewhere, and then in the frame I gave it. For example, assuming X-coordinate 200 with width 128 removes it all from the screen.
Here's how I instantiate the view controller:
myPopover = [[PopupVC alloc] initWithFrame:CGRectMake(100, 47, 128, 150)];
And the initialization 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 anyone know why this is happening? When registering a frame, it indicates exactly what I entered, but it is obviously not a frame that is being placed in the view. As another test, I made precise measurements that clearly showed they were in different locations. Very strange, any help is appreciated.
thank
source to share
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 the supervisor
self.view
|[ ]|
|[ ]|
|[staticTableView ]|
|[ ]|
|[ ]|
If you set a frame equal to the image below.
staticTable = [[UITableView alloc] initWithFrame:frame style:UITableViewStylePlain];
self.view
| [ | ]
| [ | ]
| [static|TableView]
| [ | ]
| [ | ]
source to share