0

I am a newbie, trying hard to make my first app. I would like to change the size of a (bezierpath) object(?) made by PaintCode by receiving a value from a UISlider. Can anyone help me what is wrong with my code below and how to make it work?

int heightOfBubble = 120;

- (IBAction)widthOfBubble:(id)sender {
NSLog(@"slider value = %f", self.slider.value);
[slider addTarget:self action:@selector(drawRect:) forControlEvents:UIControlEventValueChanged];
}


- (void)drawRect:(CGRect)rect {
label.text = [NSString stringWithFormat:@"%f", self.slider.value];
NSLog(@"slider value = %f", self.slider.value);
[BubbleText10 drawBubbleButtonWithText2:@"안개비 조명은 하예 흔들리는 내 몸을 감싸고~~ 술에 취에 비틀거리는 하~예 나의 모습 이제는 싫어~ 삐리비립" number:12 numberOfWidth:widthOfBubble numberOfHeight:heightOfBubble condition: NO];

And I got the following error;

Mar 19 00:55:45  BubbleText03[44457] <Error>: CGContextRestoreGState: invalid context 0x0. Backtrace:
  <+[BubbleText10 drawBubbleButtonWithText2:number:numberOfWidth:numberOfHeight:condition:]+4941>
   <-[BubbleView drawRect:]+421>
    <-[UIApplication sendAction:to:from:forEvent:]+83>
     <-[UIControl sendAction:to:forEvent:]+67>
      <-[UIControl _sendActionsForEvents:withEvent:]+444>
       <-[UISlider endTrackingWithTouch:withEvent:]+255>
        <-[UIControl touchesEnded:withEvent:]+620>
         <-[UIWindow _sendTouchesForEvent:]+2747>
          <-[UIWindow sendEvent:]+4011>
           <-[UIApplication sendEvent:]+371>
            <__dispatchPreprocessedEventFromEventQueue+3248>
             <__handleEventQueue+4879>
              <__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__+17>
               <__CFRunLoopDoSources0+556>
                <__CFRunLoopRun+918>
                 <CFRunLoopRunSpecific+420>
                  <GSEventRunModal+161>
                   <UIApplicationMain+159>
                    <main+111>
                     <start+1>

Many thanks in advance.

Lee
  • 41
  • 1
  • 8

1 Answers1

0

Instead of @selector(drawRect:) use @selector(setNeedsDisplay).


Documentation:

- (void)drawRect:(CGRect)rect;

… This method is called when a view is first displayed or when an event occurs that invalidates a visible part of the view. You should never call this method directly yourself. To invalidate part of your view, and thus cause that portion to be redrawn, call the setNeedsDisplay or setNeedsDisplayInRect: method instead.

Even if it says directly yourself and you are not calling it directly yourself, it still applies to your case.

— PaintCode Support

Tricertops
  • 8,492
  • 1
  • 39
  • 41