SwipeTableView icon indicating copy to clipboard operation
SwipeTableView copied to clipboard

点击item, 对应的界面没有显示, 要滑动才能展示

Open chaoxcheng opened this issue 7 years ago • 14 comments

进入的时候展示的是item0对应的tableView视图, 只有左右滑动才能展示接下来的item1, item2, item3的界面, 而点击item则不能展示, 这是一个BUG吧= =

chaoxcheng avatar Jul 21 '16 03:07 chaoxcheng

请问你是点击segment后,设置swipetableview滚动到相应item的index(调用scrollToItemAtIndex:animated:)后,依然是这样吗?

liangdrime avatar Jul 21 '16 03:07 liangdrime

有调用这个方法, 你的demo也是有这个问题的

chaoxcheng avatar Jul 21 '16 05:07 chaoxcheng

走了你说的这个方法, 但是貌似没什么用

chaoxcheng avatar Jul 21 '16 05:07 chaoxcheng

明白了。很抱歉啊,demo是为了模拟真实的数据方式,所以我做的是滚动到相应的index才请求数据的(本来demo只想提供一次性请求数据,这种方式只是给人做参考,结果忘了注了——这个怪我)。而点击切换忘记了设置请求数据,只在滚动结束后设置了请求数据。现在:

数据修改成一次性请求数据

    // 根据滚动后的下标请求数据
//    [self getDataAtIndex:0];

    // 一次性请求所有item的数据
    [self getAllData];

或者在segment的点击事件中也做数据请求的处理

- (void)changeSwipeViewIndex:(UISegmentedControl *)seg {
    [_swipeTableView scrollToItemAtIndex:seg.selectedSegmentIndex animated:NO];
    // request data
    [self getDataAtIndex:seg.selectedSegmentIndex];
}

liangdrime avatar Jul 21 '16 05:07 liangdrime

是这样啊, 明白了

chaoxcheng avatar Jul 21 '16 05:07 chaoxcheng

还有一个问题就是 这3个item对应的视图不好跟对应的控制器结合起来

chaoxcheng avatar Jul 21 '16 06:07 chaoxcheng

最好是以子控制器的形式添加进来, 把逻辑分开

chaoxcheng avatar Jul 21 '16 06:07 chaoxcheng

这个并不打算加入子控制器的方式来实现这个控件,不过之前有人使用这个项目时也是用VC的view来做item的,用的VC管理自己的view的,他用的效果也不错

liangdrime avatar Jul 21 '16 06:07 liangdrime

能说说为什么不打算用这种方式吗

chaoxcheng avatar Jul 21 '16 09:07 chaoxcheng

这个没什么原因吧,就是个人习惯吧。我本身就不太喜欢添加子控制的方式去写代码。与其用很多控制器,我就会用vm了。这个纯属个人原因。你要是有兴趣的话,你可以尝试着实现一下😄😄😄

liangdrime avatar Jul 21 '16 09:07 liangdrime

po主, 你好! 我这里又出现一些小问题我不知道是我原因还是你这边的原因, 我点击cell跳转是正常的, 但是当我pop到上一层的时候, 控制台会输出这些东西:

2016-07-26 11:20:45.586 CYGold[8686:470572] the behavior of the UICollectionViewFlowLayout is not defined because:
2016-07-26 11:20:45.586 CYGold[8686:470572] the item height must be less than the height of the UICollectionView minus the section insets top and bottom values, minus the content insets top and bottom values.
2016-07-26 11:20:45.586 CYGold[8686:470572] The relevant UICollectionViewFlowLayout instance is <UICollectionViewFlowLayout: 0x7fe77375c390>, and it is attached to <UICollectionView: 0x7fe775036e00; frame = (0 0; 375 569); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x7fe773743710>; layer = <CALayer: 0x7fe773746bd0>; contentOffset: {375, 0}; contentSize: {1125, 618}> collection view layout: <UICollectionViewFlowLayout: 0x7fe77375c390>.
2016-07-26 11:20:45.586 CYGold[8686:470572] Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.

对程序倒是没有什么影响, 但是总有点不好的感觉, po主能抽空看看吗?

chaoxcheng avatar Jul 26 '16 03:07 chaoxcheng

这个问题在于swipetableview设置frame的时候,设置了自适应属性autoresizingMask,由于界面跳转会影响scrollview的frame变化。所以解决办法是,去除这个设置的属性。把swipetableview的frame设置固定值就好了,比如UIScreen的bounds

liangdrime avatar Jul 26 '16 03:07 liangdrime

感谢po主, 去除了就好了, po主很厉害!

chaoxcheng avatar Jul 26 '16 08:07 chaoxcheng

好乱啊 我现在也是这样问题 我一次性请求的数据 结果也是不变啊

  • (void)changeSwipeViewIndex:(UISegmentedControl *)seg { [_swipeTableView scrollToItemAtIndex:seg.selectedSegmentIndex animated:NO]; // request data at current index //[self getDataAtIndex:seg.selectedSegmentIndex]; }

CoderBQ avatar Oct 16 '17 11:10 CoderBQ