Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 获取UITableViewCell内UICollectionViewController的旋转事件_Ios_Xamarin_Rotation_Xamarin.ios_Uicollectionview - Fatal编程技术网

Ios 获取UITableViewCell内UICollectionViewController的旋转事件

Ios 获取UITableViewCell内UICollectionViewController的旋转事件,ios,xamarin,rotation,xamarin.ios,uicollectionview,Ios,Xamarin,Rotation,Xamarin.ios,Uicollectionview,我有一个GetCell方法,它返回一个UITableViewCell,在这个方法中我想添加我的UICollectionViewController,但是我能让它显示任何内容的唯一方法是将UICollectionView从控制器添加到单元格中 在我尝试将ViewWillLayoutSubviews()方法添加到我的UICollectionViewController以检测设备旋转时的布局并调整其大小之前,这样做似乎很好。我的问题是这个ViewWillLayoutSubviews()方法从未被调用

我有一个
GetCell
方法,它返回一个
UITableViewCell
,在这个方法中我想添加我的
UICollectionViewController
,但是我能让它显示任何内容的唯一方法是将
UICollectionView
从控制器添加到单元格中

在我尝试将
ViewWillLayoutSubviews()
方法添加到我的
UICollectionViewController
以检测设备旋转时的布局并调整其大小之前,这样做似乎很好。我的问题是这个
ViewWillLayoutSubviews()
方法从未被调用

但是,当我将它放在继承自
UITableView
的类上时,它确实会被调用。但是我不能在这里执行逻辑,因为我需要更改我的
UICollectionViewCells
的宽度和高度

非常感谢您对调整
uiCollectionViewCell
大小或改进如何将
UICollectionViewController
添加到
UITableViewCell
的帮助

我的
GetCell()
方法:

public override UITableViewCell GetCell(UITableView tv)
{
    UITableViewCell cell = tv.DequeueReusableCell(CellKey);

    if (cell == null)
    {
        cell = new UITableViewCell(UITableViewCellStyle.Default, CellKey);                
    }

    UICollectionView collectionView = tileController.CollectionView;       
    cell.ContentView.AddSubview(collectionView);

    return cell;
}
My
ViewWillLayoutSubviews
在My
UICollectionViewController
中(但从未被调用):


您使用
UICollectionViewController
而不仅仅使用
UICollectionView
并覆盖
UICollectionView
LayoutSubviews
方法有何原因?如果确实需要使用视图控制器版本,则需要将其正确添加为子视图控制器:并签出“实现自定义容器视图控制器”部分。或者,我还认为您可以通过使用
UITableView访问可见单元格,在
UITableViewController
中完全实现这一点。IndexPathsForVisibleRows
,然后使用UITableView.GetCell抓取每个单元格,然后让单元格修改其内容。最后,我认为
viewwilltransitionosize
是监视视图控制器中的旋转和大小更改事件的一种更常见的方法。是否有任何原因让您使用
UICollectionViewController
而不仅仅是使用
UICollectionView
并覆盖视图的
LayoutSubviews
方法
UICollectionView
?如果确实需要使用视图控制器版本,则需要将其正确添加为子视图控制器:并签出“实现自定义容器视图控制器”部分。或者,我还认为您可以通过使用
UITableView访问可见单元格,在
UITableViewController
中完全实现这一点。IndexPathsForVisibleRows
,然后使用UITableView.GetCell抓取每个单元格,然后让单元格修改其内容。最后,我认为
viewwilltransitionosize
是监视视图控制器中的旋转和大小更改事件的更常见的方法。
public override void ViewWillLayoutSubviews()
    {
        base.ViewWillLayoutSubviews();

        nfloat mySectionInset = 20f;
        nfloat myMinSpacing = 20f;

        var screenWidth = UIScreen.MainScreen.Bounds.Width;
        nfloat defaultTileWidth;

        UICollectionViewFlowLayout flowLayout = Layout as UICollectionViewFlowLayout;
        switch (UIApplication.SharedApplication.StatusBarOrientation)
        {
            case UIInterfaceOrientation.LandscapeLeft:
            case UIInterfaceOrientation.LandscapeRight:
                defaultTileWidth = (screenWidth - (mySectionInset * 3) - myMinSpacing) / 3;
                flowLayout.ItemSize = new CGSize(defaultTileWidth, defaultTileWidth * 0.65f);
                break;
            case UIInterfaceOrientation.Portrait:
            case UIInterfaceOrientation.PortraitUpsideDown:
                defaultTileWidth = (screenWidth - (mySectionInset * 2) - myMinSpacing) / 2;
                flowLayout.ItemSize = new CGSize(defaultTileWidth, defaultTileWidth * 0.65f);
                break;
        }

        Layout.InvalidateLayout();
    }