Hillegass Chapter 24 - autoscroll challenge

Discussion in 'Mac Programming' started by petron, Aug 20, 2009.

  1. petron macrumors member

    Joined:
    May 22, 2009
    Location:
    Malmo, Sweden
    #1
    Hi,
    I just made the autoscroll challenge on ImageFun.

    The autoscrolling supposed to be controlled by a timer every tenth of a second. In My case the work seems to be done but I have experienced one side effect, maybe a bug.

    The side effect is following:

    When I press the mouse down and move it outside the window the view is scrolled smoothly controlled by the timer. All looks fine, but when I keep the mouseDown outside the window and do not dragg it for some seconds the scroll image will move to the begining of the view. If I move the mouse it will immediatly moved as it should. .

    The autoscroll method is invoked by the timer,while the timer is started from mouseDown: method. The timer is invalidated in mouseUp:

    The invoked method looks like this

    HTML:
    - (void)scrollNow
    {
        NSEvent *event = [NSApp currentEvent];
        [self autoscroll:event];
        [self setNeedsDisplay:YES];
    }
    

    Would it be a problem that the scrollNow is invoked all the time even while the mouse is not moving at all and thus the clever system finds out that maybe it is a time to reset the scroller back to start ?

    Any idea would be appreciated, speciall from those of you who are working on Hillegass cocoa programming book.

    /petron
     
  2. petron thread starter macrumors member

    Joined:
    May 22, 2009
    Location:
    Malmo, Sweden
    #2
    Are there any Hillegass - readers that managed to reach chapter 24 ?
    I really would like to verify the behaviour of autoscrolling.

    /piotr
     
  3. mdeh macrumors 6502

    Joined:
    Jan 3, 2009
    #3
    On chapter 16! :) Afraid you are going to have to wait :(
     
  4. petron thread starter macrumors member

    Joined:
    May 22, 2009
    Location:
    Malmo, Sweden
    #4
    OK mdeh,
    I will wait. Let me know how it behaves at your place when you reach chapter 24. Works fine initailly but a bit irritating when the long mouse press with no movement activity causes a reset of auto scroll possition.
    /piotr
     
  5. John Baughman macrumors member

    Joined:
    Oct 27, 2003
    #5
    Hi Peron,

    In response to your post in my thread re Chapter 26...

    Yes I have completed this challenge and my scroolNow method looks like this.

    Code:
    - (void)scrollNow:(NSTimer*)aTimer
    {
    	NSEvent *event = [NSApp currentEvent];
    	[self autoscroll:event];
    	[self setNeedsDisplay:YES];
    }
    Just like yours except for the:(NSTimer*)aTimer. I think you just left it off in your post because when I comment it out it will not work for me.

    I am not getting the behavior you describe. I click and drag outside the window, and once it is completely scrolled it stops scrolling no mater how long I hold the mouse down.

    Maybe the problem is in your mouseDown event. Here is my code for that...

    Code:
    - (void)mouseDown:(NSEvent *)event;
    {
    	NSPoint p = [event locationInWindow];
    	downPoint = [self convertPoint:p fromView:nil];
    	timer = [[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(scrollNow:) userInfo:nil repeats:YES] retain];
    	//[self setNeedsDisplay:YES];
    }
    John
     
  6. petron thread starter macrumors member

    Joined:
    May 22, 2009
    Location:
    Malmo, Sweden
    #6
    Hi, John.

    Yes my functions are nearly the same and I do have the (NSTimer *)mTimer as well. Any way I decided to copy your mouseDown to be exact copy and I still got the problem.
    Then I realized that you are not using the garbage collection while I do.

    So I went to "Target" changed the Garbage Collection to "unsuported", added in the code the retain and release, build it and now it works.

    Seems like the Garbage Collector thinks that I pressed the mouse down for too long period without movements and it releases the timer. Seems strange. There is a chapter in the book about the garbage collectors, so maybe I will find out later what has happend and how to prevent from that behaviour.

    Thanks again
    /petron
     

Share This Page