简体   繁体   中英

how to cascade uitableview's width to its custom table view cell?

I have a certain sized UIView used as a container of a UITableView. I use a subclass of UITableViewCell in my table view.

The problem is that my custom table view cell can not get the proper width from the UITableVIew. This is how I create the table view categoryListView = [[UITableView alloc] initWithFrame:categoryListContainer.bounds style:(UITableViewStylePlain)];

This is how I create the custom table view cell.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == categoryListView) {

        static NSString *CellIdentifier = @"MenuCategoryListIdentifier";

        MenuCategoryListCellView *cell = (MenuCategoryListCellView*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            // create dynamically
            cell = [[MenuCategoryListCellView alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:CellIdentifier];
        }
        ....

I wish to be able to get the correct cell bounds to in my MenuCategoryListCellView's initWithStyle method to draw my UI controls. But I don't know how to pass the value down.

Help will be appreciated!

Leo

The system will send the layoutSubviews message to your cell when the cell is resized. Override that method to lay out the UI controls according to the cell's current size.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM