简体   繁体   中英

ScrollView in Custom Cell on TableView iOS

I have custom cell on my table view which I've created with nib file. I have there 2 horizontal scrollViews . Target platform is iOS 7.

On Cell XIB file I've created "constrants" for every tableView (because I'm using 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. I have to scroll my tableView to recreate cell and than it is working again.

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. 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. But you need to execute the code inside this method even after coming back. For this you have to call setNeedsLayout

[self setNeedsLayout ];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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