Loading RTF Problem

  • Hi everybody.

    I know this has been asked before, but I could not find any clear
    answers on the list or anything that worked.

    I'm using the standard NSDocument methods for saving and loading.
    Saving works fine, as I can open it up in TextEdit. However, it won't
    load it back into my textview. Here is the code from MyDocument.m.

    - (NSData *)dataRepresentationOfType:(NSString *)aType
    {
        return [textView RTFFromRange:NSMakeRange(0, [[textView string]
    length])];
    }

    - (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType
    {
    [textView replaceCharactersInRange:NSMakeRange(0, [[textView string]
    length]) withRTF:data];
    return YES;
    }

    Again, saving works fine. Loading doesn't. Can some tell me why this
    won't work? Thanks.
    - Luke
  • On Oct 24, 2007, at 4:38 PM, Luke Pike wrote:

    > Hi everybody.
    >
    > I know this has been asked before, but I could not find any clear
    > answers on the list or anything that worked.
    >
    > I'm using the standard NSDocument methods for saving and loading.
    > Saving works fine, as I can open it up in TextEdit. However, it
    > won't load it back into my textview. Here is the code from
    > MyDocument.m.
    >
    > - (NSData *)dataRepresentationOfType:(NSString *)aType
    > {
    > return [textView RTFFromRange:NSMakeRange(0, [[textView string]
    > length])];
    > }
    >
    > - (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType
    > {
    > [textView replaceCharactersInRange:NSMakeRange(0, [[textView
    > string] length]) withRTF:data];
    > return YES;
    > }
    >
    > Again, saving works fine. Loading doesn't. Can some tell me why
    > this won't work? Thanks.
    > - Luke

    Most likely because loadDataRepresentation is called before your
    window (and thus "textView") is loaded.

    You can load the value for your textView in windowControlDidLoad:

    Glenn Andreas                      <gandreas...>
      <http://www.gandreas.com/> wicked fun!
    quadrium2 | build, mutate, evolve, animate  | images, textures,
    fractals, art
  • On Oct 24, 2007, at 5:51 PM, glenn andreas wrote:

    >
    > On Oct 24, 2007, at 4:38 PM, Luke Pike wrote:
    >
    >> Hi everybody.
    >>
    >> I know this has been asked before, but I could not find any clear
    >> answers on the list or anything that worked.
    >>
    >> I'm using the standard NSDocument methods for saving and loading.
    >> Saving works fine, as I can open it up in TextEdit. However, it
    >> won't load it back into my textview. Here is the code from
    >> MyDocument.m.
    >>
    >> - (NSData *)dataRepresentationOfType:(NSString *)aType
    >> {
    >> return [textView RTFFromRange:NSMakeRange(0, [[textView
    >> string] length])];
    >> }
    >>
    >> - (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)
    >> aType
    >> {
    >> [textView replaceCharactersInRange:NSMakeRange(0, [[textView
    >> string] length]) withRTF:data];
    >> return YES;
    >> }
    >>
    >> Again, saving works fine. Loading doesn't. Can some tell me why
    >> this won't work? Thanks.
    >> - Luke
    >
    > Most likely because loadDataRepresentation is called before your
    > window (and thus "textView") is loaded.
    >
    > You can load the value for your textView in windowControlDidLoad:
    >
    >
    > Glenn Andreas                      <gandreas...>
    > <http://www.gandreas.com/> wicked fun!
    > quadrium2 | build, mutate, evolve, animate  | images, textures,
    > fractals, art
    >

    Of course! Your exactly right, Glenn. Loading works fine now. Thanks!
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today