Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ghousemd

macrumors newbie
Original poster
Jun 25, 2011
21
0
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;
}
 
Last edited by a moderator:
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.
 
table view is not displaying anything

I'm not sure what you mean by "dictionary string". Would you care to elaborate?

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
 
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
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.
 
clarification

above i have specified the entire code with plist structure and let me know how to specify section in this example
 
root dictionary
book dictionary
hhh dictionary
name hhh
meaning bye
go dictionary
name go
meaning going

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

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.
 
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
 
Last edited by a moderator:
Code:
    NSString *pListPath = [[NSBundle mainBundle] pathForResource:@"Book" ofType:@"plist"];
	NSDictionary *dictionary = [[NSDictionary alloc] initWithContentsOfFile:pListPath];
	NSLog(@"..%@",dictionary);

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.
 
Last edited:
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"];
		[COLOR=red]aray=ob.strName;[/COLOR]
        		[arrBooks addObject:ob];
       
		[ob release];
		ob= nil;
	}
    	NSLog(@"No fof books :%i",[arrBooks count]);
      // NSLog(@"%i",[aray count]);
}

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?
 
Last edited by a moderator:
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"];
		[COLOR=red]aray=ob.strName;[/COLOR]
        		[arrBooks addObject:ob];
       
		[ob release];
		ob= nil;
	}
    	NSLog(@"No fof books :%i",[arrBooks count]);
      // NSLog(@"%i",[aray count]);
}

This code in red doesn't make sense.
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
 
Last edited by a moderator:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.