Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting UITableView's Frame Does Not Work Correctly

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

like image 369
Kyle Rosenbluth Avatar asked Jun 13 '26 20:06

Kyle Rosenbluth


2 Answers

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]
 |      [      |         ]
 |      [      |         ]
like image 93
bitmapdata.com Avatar answered Jun 15 '26 10:06

bitmapdata.com


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.

like image 35
SreeHarsha Avatar answered Jun 15 '26 10:06

SreeHarsha