Search code examples
iosfontsuiscrollviewpopoverdelegation

Change a font from a popover for underling scrollview


I am using Xcode 4.5, targeting iOS5 and above. I have a popover that allows a user to change the fonts of the underlying view. When tapping on the font, the change does not occur, until after I close the popover and the underling view and reopen. It is set up for delegation. And the receiving view does import the the FontsPopoverViewDelegate. Any help toward a solution would be greatly appreciated.

The Delegate methods for fonts:

@protocol FontsPopoverViewDelegate <NSObject>
- (void)fontResize:(float)size forView:(int)type;
- (void)font:(int)fontID forView:(int)fView;
- (int)getFontForView:(int)fView;
- (float)getFontSizeForView:(int)fView;
@end

Methods implemented in underlying view:

- (void)fontResize:(float)size forView:(int)type {
  fontSizes[type] = size;
  [self invalidate];
}

- (void)font:(int)fontID forView:(int)fView {
  fontIds[fView] = fontID;
  [self invalidate];
}

- (int)getFontForView:(int)fView {
  return fontIds[fView];
  [self invalidate];
}

- (float)getFontSizeForView:(int)fView {
  return fontSizes[fView];
  [self invalidate]; // added to spark a reaction from the view
}

-(void) invalidate {
  NSLog(@"Invalidate called");
  [self saveTextChanges];
  [self refreshBodyText];
  [self refreshBackground];
  [self refreshBodyText];
  [self refreshDateFont];
  [self refreshTitleFont];
}

Any help would be greatly appreciated.


Solution

  • I solved this by posting a notification from the font popover to the underlying view. In the underlying view, I added the call... [self viewWillAppear:YES];

    Now, it is working perfectly.

    I have a slider, within the Fonts popover, that changes the size and a notification and calling viewWillAppear within the notification works the same as the font change.

    - (void)aFontChanged:(NSNotification *)notification
    {
        NSLog(@"aFontChanged notification?");
        [self viewWillAppear:YES];
        [self refreshBodyText];
        [self refreshDateFont];
        [self refreshTitleFont];
    }
    
    - (void)aFontSizeChanged:(NSNotification *)notification
    {
        NSLog(@"aFontSizeChanged notification?");
        [self viewWillAppear:YES];
        [self refreshBodyText];
        [self refreshDateFont];
        [self refreshTitleFont];
    }