0

I have a grouped table view with custom cells in it, and it contains many cells (i.e. scrollable), there is a scroll view in every cell (which contains a UILabel), I've set up that scroll view properly (made its content size larger than its frame size for the scroll to work properly and then added it as a sub-view on the custom cell), however, the text on the label that is inside this scroll view appears but not scrollable (no scroll bars, no scrolling ...), the only scrollable object on the screen is the default scroll view of the grouped table view.

how can i get the mini scroll view to scroll properly ?

thank you in advance.

JAHelia
  • 6,934
  • 17
  • 74
  • 134
  • How would the app know if you mean to scroll the text or if you mean to scroll the table? Even if your scrollview only takes up part of the cell view I think your users will be confused by the interface and think that it doesn't work. – ader Dec 20 '11 at 16:41
  • the app would know that as follows: when i tap within the mini-scroll view frame it must scroll inside each cell (if there is large text of course), and if i tap outside the borders of any cell's frame, the main scroll of the tableview must take effect and provide the desired scroll. – JAHelia Dec 20 '11 at 16:49
  • How high are you thinking your cells will be? I think your users will be confused by the interface and think that it doesn't work. I recommend you re-consider your UI design. Maybe a scrollview with vertical paging would work better. – ader Dec 20 '11 at 16:55
  • the cells' row height = 137 which very high and makes a good room for a scroll. I guess a vertical paging with a scroll view is somehow complicated, im saying this 'coz i did not try such thing before, wat do you think ade ? – JAHelia Dec 20 '11 at 17:32
  • 1
    At 137 high you're probably better with scrollviews like you originally thought. I assumed your cells would be higher than this when I suggested paging scrollview. I would suggest making the scrollview background a different color to the cell background so user's are less likely to be confused. – ader Dec 20 '11 at 17:38
  • this is a very important hint, i appreciate it. take a +1 for it – JAHelia Dec 20 '11 at 18:00

2 Answers2

2

Are you implementing touchesBegan and touchesEnded in your scrollview?

- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)event 
{
    [super touchesBegan:touches withEvent:event];
    [[self nextResponder] touchesBegan:touches withEvent:event];
}


- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent *)event 
{
    [super touchesEnded:touches withEvent:event];
    [[self nextResponder] touchesEnded:touches withEvent:event];
}

If not, make a class for your scrollview (scrollview subclass) and implement them therein.

ader
  • 5,403
  • 1
  • 21
  • 26
  • why should i subclass the scroll view and customize the touches began and touches ended methods ? what should i put in these methods ? – JAHelia Dec 20 '11 at 18:03
  • 1
    I'm thinking you need to propagate the touches (as above). – ader Dec 21 '11 at 10:53
  • i've subclassed my uiscrollview and put these methods with NSLogs inside them for testing, but the log messages did not show! some people say that I have to detect gestures on the mini-scroll view to indicate whether to scroll it or to scroll the main scroll view of the table view, but do not know how to do it, do you have an idea about it ? – JAHelia Dec 22 '11 at 11:05
  • 1
    Have you seen this: http://stackoverflow.com/questions/4324514/horizontal-uiscrollview-inside-a-uitableviewcell – ader Dec 22 '11 at 11:33
  • 1
    ya I saw it before, and I have a test project that has this feature working (i can send it to you if you want; but couldn't find your email in the profile), however, my case is exactly like this case but the scrolling must be vertical not horizontal, some geek told me that the touches methods (you provided) won't work in my case, instead I have to use gesture recognizer methods ('coz scroll view now supports gesture recognizers) to recognize which scroll to run, the inner small one or the bigger outer one, but do not know how to do this thing :( – JAHelia Dec 22 '11 at 12:58
0

Here's the full code of what should be written in the subclass of the scroll view.

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    if (self.dragging) {
        [super touchesBegan:touches withEvent:event];
    } else {
        [self.superview touchesBegan:touches withEvent:event];
    }
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    if (self.dragging) {
        [super touchesMoved:touches withEvent:event];
    } else {
        if ([self.delegate isKindOfClass:[UITableViewCell class]]) {
            [(UITableViewCell *)self.delegate touchesCancelled:touches withEvent:event];
        }

        [self.superview touchesMoved:touches withEvent:event];
    }
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    if (self.dragging) {
        [super touchesEnded:touches withEvent:event];
    } else {
        [self.superview touchesEnded:touches withEvent:event];
    }
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
    if (self.dragging) {
        [super touchesCancelled:touches withEvent:event];
    } else {
        [self.superview touchesMoved:touches withEvent:event];
    }
}

In the touchesMoved there's some extra code based on a bug I was encountering. To start, if your self.delegate is not the UITableViewCell, than replace that property with a property to your cell.

The cell needs to retrieve the cancel touch event during movement to prevent the undesired results. It can be easily reproducible as follows.

  • Highlight the cell (assuming the scroll view is over the whole cell, if not highlight the scroll view)
  • While the cell is highlighted, drag the table view
  • Select any other cell and now the previously highlighted cell will retrieve the didSelectCell state

Another point to mention is that order matters! If the self.delegate is not called before the self.superview then the highlighted state wont happen.

cnotethegr8
  • 7,342
  • 8
  • 68
  • 104