简体   繁体   English

如何将uitableview的宽度级联到其自定义表格视图单元格?

[英]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. 我有一个特定大小的UIView用作UITableView的容器。 I use a subclass of UITableViewCell in my table view. 我在表格视图中使用UITableViewCell的子类。

The problem is that my custom table view cell can not get the proper width from the UITableVIew. 问题是我的自定义表格视图单元格无法从UITableVIew获得适当的宽度。 This is how I create the table view categoryListView = [[UITableView alloc] initWithFrame:categoryListContainer.bounds style:(UITableViewStylePlain)]; 这就是我创建表视图的方式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. 我希望能够在MenuCategoryListCellView的initWithStyle方法中获取正确的单元格边界以绘制UI控件。 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. 调整单元格的大小时,系统将把layoutSubviews消息发送到您的单元格。 Override that method to lay out the UI controls according to the cell's current size. 重写该方法以根据单元格的当前大小布置UI控件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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