problem with plist in tableview

Discussion in 'iOS Programming' started by ghousemd, Jun 25, 2011.

  1. ghousemd, Jun 25, 2011
    Last edited by a moderator: Jun 28, 2011

    ghousemd macrumors newbie

    Joined:
    Jun 25, 2011
    #1
    hi i am creating a tabbar app where in second tab i am creating a table and trying to display the info using plist but my table view is not displaying anything and my plist is in the format given below like that i have 300 names how should i can retrieve plist and display it in table view plz replay me thanks in advance.
    plist format :

    root dictionary
    book dictionary
    hhh dictionary
    name hhh
    meaning bye
    go dictionary
    name go
    meaning going
    like dis i have defined plist and i want to retrieve and diplay in tableview
    Code:
    - (void)viewDidLoad
    {
    NSDictionary *contactList = [propertyList readFromArchive:@"Book"];
        [self setBook:[contactList objectForKey:@"book"]];
        [self setTitle:@"Contacts"];
        [self myTable];
        NSLog(@"gggggg");
        }
    
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
    
        // Return the number of sections.
        return 1;
    }
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
    
        // Return the number of rows in the section.
        //return [dag count];
        return [[[self book] allKeys] count];
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    NSArray *keys = [[[self book] allKeys]sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]; NSString *key = [keys objectAtIndex:[indexPath row]];
        NSDictionary *contact = [[self book] objectForKey:key];
        static NSString *CellIdentifier = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        }
        cell.textlabel.text =[contact objectForKey:@"name"];
        return cell;
    }
    
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    Post your code.

    Please use shorter sentences when describing problems.
    Please put a period (full stop) at the end of each sentence.
    If we can't understand your questions, then we can't provide answers.
     
  3. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    I'm not sure what you mean by "dictionary string". Would you care to elaborate?
     
  4. ghousemd thread starter macrumors newbie

    Joined:
    Jun 25, 2011
    #4
    table view is not displaying anything

    hi i need ur help very badly.i want retrieve plist and i am not able do that may be the format i have taken is wrong plz help and i am creating a dictionary app for that how plist should be defined and retrieve
     
  5. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    I'm still unsure what the format/structure of your plist is. What type is the root? Are there arrays? What is the hierarchy, if any? Perhaps if you were to include a sample of the plist file itself, it might be more clear.
     
  6. ghousemd thread starter macrumors newbie

    Joined:
    Jun 25, 2011
    #6
    clarification

    above i have specified the entire code with plist structure and let me know how to specify section in this example
     
  7. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #7
    If you could include a sample of the actual plist file itself, complete with XML tags, that would help. Here's an example of what I'm looking for:

    Code:
    <plist version="1.0">
    <dict>
    <key>Label</key>
    <string>com.mortbay.jetty</string>
    <key>ServiceDescription</key>
    <string>Jetty JSP Container</string>
    <key>OnDemand</key>
    <false/>
    <key>WorkingDirectory</key>
    <string>/Library/Jetty/Current</string>
    <key>EnvironmentVariables</key>
    <dict>
    <key>JETTY_HOME</key>
    <string>/Library/Jetty/Current</string>
    <key>JAVA_HOME</key>
    <string>/Library/Java/Home</string>
    </dict>
    <key>ProgramArguments</key>
    <array>
    <string>/usr/bin/java</string>
    <string>-jar</string>
    <string>/Library/Jetty/Current/start.jar</string>
    <string>/Library/Jetty/Current/etc/jetty.xml</string>
    </array>
    <key>Sockets</key>
    <dict>
    <key>Listeners</key>
    <dict>
    <key>SockServiceName</key>
    <integer>8808</integer>
    <key>Bonjour</key>
    <false/>
    </dict>
    </dict>
    <key>UserName</key>
    <string>servlet</string>
    </dict>
    </plist>
    When you say you want to know "how to specify section", do you mean section as in what is used for a grouped table?

    P.S. Also, please refrain from editing your original post and instead simply include any follow-up information in a new post. This helps keep the "train" of the thread, especially responses, on track.
     
  8. ghousemd, Jun 29, 2011
    Last edited by a moderator: Jun 29, 2011

    ghousemd thread starter macrumors newbie

    Joined:
    Jun 25, 2011
    #8
    table view

    Code:
    - (void)viewDidLoad
    {
        aray=[[NSMutableArray alloc]init];
        //[window addSubview:nav]; 
        NSString *pListPath = [[NSBundle mainBundle] pathForResource:@"Book" ofType:@"plist"];
    	NSDictionary *dictionary = [[NSDictionary alloc] initWithContentsOfFile:pListPath];
    	NSLog(@"..%@",dictionary);
    	
    	arrBooks = [[NSMutableArray alloc] init];
       	NSArray *allBooks = [dictionary allKeys];
    	for (NSString *strKey in allBooks) {
    		
    		NSDictionary *bookIs = [dictionary objectForKey:strKey];
    		
    		BookBO *ob  = [[BookBO alloc] init];
    		
    		ob.strName = [bookIs objectForKey:@"name"];
    		ob.strCountry = [bookIs objectForKey:@"country"];
    		aray=ob.strName;
            		[arrBooks addObject:ob];
           
    		[ob release];
    		ob= nil;
    	}
        	NSLog(@"No fof books :%i",[arrBooks count]);
          // NSLog(@"%i",[aray count]);
    }
    in that i need to retrieve all names and store in a array i does not know how to do that if any body know jst let me know
     
  9. RonC, Jun 29, 2011
    Last edited: Jun 29, 2011

    RonC macrumors regular

    Joined:
    Oct 18, 2007
    Location:
    Chicago-area
    #9
    a) Does the file exist? What's in it (i.e., can you post that)?
    b) What prints to the console when you run this part of the code? That will have the structure of your dictionary and we can help you better once we can see it.
     
  10. jiminaus, Jun 29, 2011
    Last edited by a moderator: Jun 30, 2011

    jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #10
    This code in red doesn't make sense. At the top of the code you alloc and init an NSMutableArray object and store the pointer to that object in aray. The code in red then overwrites the pointer in aray with the pointer to the NSString object in ob's strName property.

    What did you want this line of code to actually do?
     
  11. ghousemd, Jun 29, 2011
    Last edited by a moderator: Jun 30, 2011

    ghousemd thread starter macrumors newbie

    Joined:
    Jun 25, 2011
    #11
    k i want to store all names in an array i dont know how to do that let me know if u have the answer
     
  12. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #12
    What resources are you using to learn Objective-C / iOS programming? Be specific as possible.
     

Share This Page