Read from text file won't work?

Discussion in 'iOS Development' started by Collateral, Oct 24, 2009.

  1. Collateral

    Collateral Active Member

    Joined:
    Sep 23, 2007
    Messages:
    1,974
    Likes Received:
    6
    Device:
    iPhone 3GS (Black)
    Alright.. this should be an easy one... i think i'm missing something stupid..

    I have an object "Strain" with an instance field "description" which contains a string in with the format:

    [OBJC]description

    Please Register or Log in to view images

    "filename.txt"[/OBJC]

    I have the below in order to retrieve the text from the file:

    [OBJC]
    -removed
    [/OBJC]

    It does some other stuff too.. just ignore that..


    But anyway, it compiles, builds, and runs in the simulator with no problems, no errors, no warnings.

    But it doesnt show the text. My UITextView "strainDescription" comes up empty.

    What am i doing wrong?
  2. Axis

    Axis Super Moderator Staff Member

    Joined:
    Dec 2, 2007
    Messages:
    6,288
    Likes Received:
    133
    Device:
    iPhone 4S (White)
    Post more of your code.

    What is: description

    Please Register or Log in to view images

    "filename.txt" ?

    Is that an attempt to set the 'description' ivar to that NSString constant?

    EDIT: Also, is 'filename.txt' in the app bundle? Try dropping it in your / directory and accessing via "/filename.txt" - just for testing purposes
  3. Collateral

    Collateral Active Member

    Joined:
    Sep 23, 2007
    Messages:
    1,974
    Likes Received:
    6
    Device:
    iPhone 3GS (Black)
    it is a reference to an instance field on one of my "Strain" Objects

    [OBJC]-removed[/OBJC]
    ------------------double post merged------------------
    It is. Its all been added and whatnot.
  4. Axis

    Axis Super Moderator Staff Member

    Joined:
    Dec 2, 2007
    Messages:
    6,288
    Likes Received:
    133
    Device:
    iPhone 4S (White)
    The code for that constructor method maybe faulty. Also, you seem to use 'view' and 'viewcontroller' interchangeably, which is not a good idea.
  5. Collateral

    Collateral Active Member

    Joined:
    Sep 23, 2007
    Messages:
    1,974
    Likes Received:
    6
    Device:
    iPhone 3GS (Black)
    ViewController is the name of the actual file. View is what i reference it as.

    eg.

    StrainViewController *strainView


    But uhhh I'll update the first Post with a better example of the code.
  6. Axis

    Axis Super Moderator Staff Member

    Joined:
    Dec 2, 2007
    Messages:
    6,288
    Likes Received:
    133
    Device:
    iPhone 4S (White)
    That's my point. Even though the code you write may be for your eyes only, violating naming conventions will catch up to you at some point.

    [objc]
    NSString *myString = [[NSString alloc] initWithContentsOfFile:[strain description] encoding:NSUTF8StringEncoding error:NULL];
    [/OBJC]
  7. Collateral

    Collateral Active Member

    Joined:
    Sep 23, 2007
    Messages:
    1,974
    Likes Received:
    6
    Device:
    iPhone 3GS (Black)
    Thats what i was doing.. you just changed the variable names.

    Please Register or Log in to view images



    But i did it anyway. and it does the same thing... no warnings, no errors, no text.
  8. Axis

    Axis Super Moderator Staff Member

    Joined:
    Dec 2, 2007
    Messages:
    6,288
    Likes Received:
    133
    Device:
    iPhone 4S (White)
    No that's not exactly what you were doing. Read the docs. There are four methods that look very similar. Two are instance methods, two are class methods.

    Note the difference:

    You were using the latter, I posted the former. For your purposes, the former works.
  9. Collateral

    Collateral Active Member

    Joined:
    Sep 23, 2007
    Messages:
    1,974
    Likes Received:
    6
    Device:
    iPhone 3GS (Black)
    Your right, i did miss the difference at first.. but uh... it still doesnt work :/

    [OBJC]-removed
    [/OBJC]
  10. NolesFans

    NolesFans New Member

    Joined:
    Sep 23, 2008
    Messages:
    404
    Likes Received:
    0
    Device:
    iPod touch
    Strain *strain = (Strain *)[appDelegate.strains objectAtIndex:indexPath.row];
    I am bit curious of this. Strain is NSObject, Im assumed.

    objectAtIndex, it is normally uses for NSArray or NSDictionary.

Share This Page