Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Hope you won't mind, If I write some code for you. Don't just copy and paste it. Try to understand the way it is. So that you can tackle this kind of requirement in the future.</strong></p> <p>I had your data in the <code>plist</code> and extracted it to the <code>NSMutableDictionary</code> and then <code>NSMutableArray</code> like this.</p> <pre><code>// In the viewDidLoad: method NSMutableDictionary *plistData = [NSMutableDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"Countries" ofType:@"plist"]]; sectionedArray = [plistData objectForKey:@"Country"]; </code></pre> <p>then the following <code>tableView</code> methods.</p> <pre><code>- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // Return the number of sections. return [sectionedArray count]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // Return the number of rows in the section. NSMutableArray *array = [[sectionedArray objectAtIndex:section] objectForKey:@"citys"]; return [array count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier];; } // Configure the cell... NSMutableArray *array = [[sectionedArray objectAtIndex:indexPath.section] objectForKey:@"citys"]; NSDictionary *dict = [array objectAtIndex:indexPath.row]; cell.textLabel.text = [dict valueForKey:@"cityName"]; return cell; } // Override to support conditional editing of the table view. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the specified item to be editable. return YES; } // Override to support editing the table view. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { // Delete the row from the data source NSMutableArray *array = [[sectionedArray objectAtIndex:indexPath.section] objectForKey:@"citys"]; [array removeObjectAtIndex:indexPath.row]; [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; NSLog(@"Sectioned array %@", sectionedArray); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload