我有一个项目有一个按钮,允许用户在列表视图(UITableView)和网格视图(UICollectionView)之间切换. 
 
但我不知道要做什么请帮帮我. (对不起英语不好)
但我不知道要做什么请帮帮我. (对不起英语不好)
解决方法
 假设您的控制器具有名为tableView的UITableView属性和名为collectionView的UICollectionView属性.在您的viewDidLoad中,您需要添加起始视图.我们假设这是表格视图: 
  
  
 
        - (void)viewDidLoad
{
    self.tableView.frame = self.view.bounds;
    [self.view addSubview:self.tableView];
} 
 然后在你的按钮回调中,交换意见:
- (void)buttonTapped:(id)sender
{
     UIView *fromView,*toView;
     if (self.tableView.superview == self.view)
     {
         fromView = self.tableView;
         toView = self.collectionView;
     }
     else
     {
         fromView = self.collectionView;
         toView = self.tableView;
     }
     [fromView removeFromSuperview];
     toView.frame = self.view.bounds;
     [self.view addSubview:toView];
} 
 如果你想要一个花哨的动画,你可以使用[UIView transitionFromView:toView:duration:options:completion:]改为:
- (void)buttonTapped:(id)sender
{
     UIView *fromView,*toView;
     if (self.tableView.superview == self.view)
     {
         fromView = self.tableView;
         toView = self.collectionView;
     }
     else
     {
         fromView = self.collectionView;
         toView = self.tableView;
     }
     toView.frame = self.view.bounds;
     [UIView transitionFromView:fromView
                         toView:toView
                       duration:0.25
                        options:UIViewAnimationTransitionFlipFromright
                     completion:nil];
}