简体   繁体   English

TableView iOS上的“自定义单元格”中的ScrollView

[英]ScrollView in Custom Cell on TableView iOS

I have custom cell on my table view which I've created with nib file. 我在用nib文件创建的表格视图中有自定义单元格。 I have there 2 horizontal scrollViews . 我有2个水平scrollViews Target platform is iOS 7. 目标平台是iOS 7。

On Cell XIB file I've created "constrants" for every tableView (because I'm using autolayout ). 在Cell XIB文件上,我为每个tableView创建了“常量”(因为我正在使用autolayout )。

On my Custom cell implementation file I have such code: 在我的自定义单元实现文件中,我有以下代码:

-(void)layoutSubviews
{

   self.SwitchPageSV.contentSize = CGSizeMake(960, 240);
   self.SwitchPageSV.scrollEnabled = YES;
   self.SwitchPageSV.delegate = self;

   self.ButtonsSV.contentSize = CGSizeMake(400, 40);
   self.SwitchPageSV.scrollEnabled = YES;

}

And it is working like a charm. 它的工作就像一种魅力。 But when I go from this table view to other View Controller and go back, scroll view does not work anymore. 但是,当我从此表视图转到其他View Controller并返回时,滚动视图不再起作用。 I have to scroll my tableView to recreate cell and than it is working again. 我必须滚动我的tableView来重新创建单元格,然后它才能再次工作。

Reloading data doesn't help: 重新加载数据无济于事:

I was trying to define those values on: 我试图在以下位置定义这些值:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

on my viewController , where I'm putting all data to this cell. 在我的viewController ,我将所有数据放到该单元格中。 But from there, my settings for scroll view are not working at all. 但是从那里开始,我的滚动视图设置根本不起作用。 I have no idea what to do with that thing. 我不知道该怎么办。 Any help? 有什么帮助吗?

This is because layoutSubviews method in your code only invokes after initialization. 这是因为代码中的layoutSubviews方法仅在初始化后调用。 But you need to execute the code inside this method even after coming back. 但是,即使返回后,也需要在此方法中执行代码。 For this you have to call setNeedsLayout 为此,您必须调用setNeedsLayout

[self setNeedsLayout ];

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

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