Populating a text view from a plist not working

Discussion in 'iOS Development' started by StevenHu, Oct 21, 2009.

  1. StevenHu

    StevenHu New Member

    Joined:
    Sep 21, 2009
    Messages:
    5
    Likes Received:
    0
    Device:
    3G iPod touch
    I followed this tutorial on making a drill-down table using the plist at http://www.iphonesdkarticles.com/2009/03/uitableview-drill-down-table-view.html I am going further by trying to populate the detail page with another string entry from the plist, but it's not working.

    The detail page has a text view on it called textView. It is supposed to receive the dictionary string.

    Here's my code:

    Code:
    // Get the definition of the present item
    NSString *definition = [dictionary objectForKey:@"Definition"];
    NSString *def = [[NSString alloc] initWithFormat:@"%@", definition];
    textView.text = def;
    [def release];
    The debugger console says, "this class is not key value coding-compliant for the key textView"

    I don't know what direction to go with this message.

    I'll appreciate any help!

    Thanks,
    Steve
  2. Steaps

    Steaps New Member

    Joined:
    Oct 24, 2007
    Messages:
    5,074
    Likes Received:
    41
    Device:
    iPod touch
    What exactly is the point of this?

    Please Register or Log in to view images


    Code:
    NSString *definition = [dictionary objectForKey:@"Definition"];
    NSString *def = [[NSString alloc] initWithFormat:@"%@", definition];
    
    Just do this:
    Code:
    NSString * definition = [NSString stringWithFormat:@"%@", [dictionary objectForKey:@"Definition"]];
    textView.text = definition;
    
    If the objectForKey@"Definition" is an string, this code will work fine.

    P.S. Wrong subform

    Please Register or Log in to view images

    http://www.ifans.com/forums/forumdisplay.php?f=53
  3. StevenHu

    StevenHu New Member

    Joined:
    Sep 21, 2009
    Messages:
    5
    Likes Received:
    0
    Device:
    3G iPod touch
    Thanks for helping. I still get the same error, though, so something is wrong somewhere else. textView is not a key, but the program thinks it is.

    Thanks for telling me about the right sub-forum!
  4. Steaps

    Steaps New Member

    Joined:
    Oct 24, 2007
    Messages:
    5,074
    Likes Received:
    41
    Device:
    iPod touch
    Are you declaring textView as a UITextView?
  5. StevenHu

    StevenHu New Member

    Joined:
    Sep 21, 2009
    Messages:
    5
    Likes Received:
    0
    Device:
    3G iPod touch
    Yes I am.
  6. Steaps

    Steaps New Member

    Joined:
    Oct 24, 2007
    Messages:
    5,074
    Likes Received:
    41
    Device:
    iPod touch
    Post the entire method from which this is being called.
  7. StevenHu

    StevenHu New Member

    Joined:
    Sep 21, 2009
    Messages:
    5
    Likes Received:
    0
    Device:
    3G iPod touch
    [OBJC]// RootViewController.m

    - (void)tableView

    Please Register or Log in to view images

    UITableView *)tableView didSelectRowAtIndexPath

    Please Register or Log in to view images

    NSIndexPath *)indexPath {

    /* Dictionary composed of Rows > Item1 > Image (string for jpg filename), Definition (string for glossary definition), Title (string for top of view), View (string for ViewController name in case I made a view controller for each definition).
    */
    //Get the dictionary of the selected data source. tableDataSource contains the plist items.
    NSDictionary *dictionary = [self.tableDataSource objectAtIndex:indexPath.row];

    //Get the children of the present item. NOT USED.
    NSArray *Children = [dictionary objectForKey

    Please Register or Log in to view images

    "Children"];

    NSString *definition = [NSString stringWithFormat

    Please Register or Log in to view images

    "%@", [dictionary objectForKey

    Please Register or Log in to view images

    "Definition"]];
    textView.text = definition;

    if([Children count] == 0) {
    /* Loads DetailViewController.xib template page: */
    DetailViewController *dvController = [[DetailViewController alloc] initWithNibName

    Please Register or Log in to view images

    "DetailView" bundle:[NSBundle mainBundle]];
    [self.navigationController pushViewController:dvController animated:YES];
    [dvController release];

    /*
    My attempt to point to dictionary item view containing title of view controller (works!). NOT USED. Trying to use template page.
    DetailViewController *dvController = [[DetailViewController alloc] initWithNibName

    Please Register or Log in to view images

    @"%@", view) bundle:[NSBundle mainBundle]];
    [self.navigationController pushViewController:dvController animated:YES];
    [dvController release];
    */


    }
    else {

    //Prepare the tableview.
    RootViewController *rvController = [[RootViewController alloc] initWithNibName

    Please Register or Log in to view images

    "RootViewController" bundle:[NSBundle mainBundle]];

    //Increment the Current View
    rvController.CurrentLevel += 1;

    //Set the title;
    rvController.CurrentTitle = [dictionary objectForKey

    Please Register or Log in to view images

    "Title"];

    //Push the new table view on the stack
    [self.navigationController pushViewController:rvController animated:YES];

    rvController.tableDataSource = Children;

    [rvController release];
    }
    }

    - (void)dealloc {
    [CurrentTitle release];
    [imageView release];
    [textView release];
    [tableDataSource release];

    [super dealloc];
    }

    ========================================

    // RootViewController.h

    #import <UIKit/UIKit.h>
    #import "DetailViewController.h"

    @interface RootViewController : UITableViewController {

    NSArray *tableDataSource;
    NSString *CurrentTitle;
    NSInteger CurrentLevel;
    IBOutlet UIImageView *imageView; //not sure where to place this - it is in DetailViewController
    IBOutlet UITextView *textView; //not sure where to place this - it is in DetailViewController
    }

    @property (nonatomic, retain) NSArray *tableDataSource;
    @property (nonatomic, retain) NSString *CurrentTitle;
    @property (nonatomic, readwrite) NSInteger CurrentLevel;
    @property (nonatomic, retain) IBOutlet UIImageView *imageView;
    @property (nonatomic, retain) IBOutlet UITextView *textView;

    @end

    ========================================

    // DetailViewController.h
    // This is the template page in which the UITextField and UIImage are updated for each row.

    #import <UIKit/UIKit.h>


    @interface DetailViewController : UIViewController {
    }

    @end

    ========================================

    // DetailViewController.m


    #import "DetailViewController.h"
    #import "RootViewController.h"


    @implementation DetailViewController

    // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
    - (void)viewDidLoad {
    [super viewDidLoad];

    self.navigationItem.title = @"Glossary"; // Title of Detail View
    }



    - (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
    // Release anything that's not essential, such as cached data
    }


    - (void)dealloc {
    [super dealloc];
    }


    @end[/OBJC]
  8. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    http://www.ifans.com/forums/showthread.php?t=137473
  9. StevenHu

    StevenHu New Member

    Joined:
    Sep 21, 2009
    Messages:
    5
    Likes Received:
    0
    Device:
    3G iPod touch
    Very good, Skylar!

    Thanks!

Share This Page