Note that there are some explanatory texts on larger screens.

plurals
  1. POTableView Showing Map Annotation Titles and Subtitles
    primarykey
    data
    text
    <p>I am trying to create a table view that shows a list of my map annotations. Each cell would contain the name(title) and address(subtitle). I'm then going to add a search bar to the table view. When I try to add the annotation titles and subtitles to an array for my table view, the array never gets any objects added to it. It's count is still 0. Any help?</p> <p>Here is how I'm adding the annotations to my map view:</p> <pre><code>for (int x = 0; x &lt; [lat count]; x++) { marketAnnotation = [[MKPointAnnotation alloc]init]; location.latitude = [[lat objectAtIndex:x]floatValue]; location.longitude = [[lon objectAtIndex:x]floatValue]; marketAnnotation.coordinate = location; marketAnnotation.title = [title1 objectAtIndex:x]; marketAnnotation.subtitle = [subtitle1 objectAtIndex:x]; [marketLocations addObject:marketAnnotation]; } [worldView addAnnotations:marketLocations]; </code></pre> <p>I have tried adding this to the loop to add the title to my table view array but the array stays empty.</p> <pre><code>[list.marketList addObject:marketAnnotation.title]; </code></pre> <p>EDIT: More code.</p> <p>RSFM is my map view. List is my table view.</p> <p>In RSFM, here is where I add the annotations to my map and add the annotation titles to the marketList array in List.</p> <pre><code>List *list = [[List alloc]init]; list.marketList = [[NSMutableArray alloc]init]; for (int x = 0; x &lt; [lat count]; x++) { marketAnnotation = [[MKPointAnnotation alloc]init]; location.latitude = [[lat objectAtIndex:x]floatValue]; location.longitude = [[lon objectAtIndex:x]floatValue]; marketAnnotation.coordinate = location; marketAnnotation.title = [title1 objectAtIndex:x]; marketAnnotation.subtitle = [subtitle1 objectAtIndex:x]; [marketLocations addObject:marketAnnotation]; [list.marketList addObject:marketAnnotation.title]; } [worldView addAnnotations:marketLocations]; NSLog(@"List Count: %d", [list.marketList count]); </code></pre> <p>List.h</p> <pre><code>@interface List : UIViewController &lt;UITableViewDelegate, UITableViewDataSource, UISearchBarDelegate&gt; { IBOutlet UISearchBar *searchBar; } @property (nonatomic, retain) NSMutableArray *marketList; @end </code></pre> <p>List.m</p> <pre><code>#import "List.h" #import "RSFM.h" #import "DTCustomColoredAccessory.h" @interface List () @end @implementation List { } @synthesize marketList; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. NSLog(@"List Count: %d", [marketList count]); } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [marketList count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *marketListIdentifier = @"SimpleTableItem"; UIImageView *image = [[UIImageView alloc]init]; image.image = [UIImage imageNamed:@"CellImage.png"]; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:marketListIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:marketListIdentifier]; cell.textLabel.font=[UIFont systemFontOfSize:16.0]; } cell.textLabel.font = [UIFont fontWithName:@"FranklinGothicStd-ExtraCond" size:20.0]; cell.textLabel.backgroundColor = [UIColor clearColor]; cell.textLabel.highlightedTextColor = [UIColor darkGrayColor]; cell.textLabel.textColor = [UIColor whiteColor]; cell.backgroundView = image; NSLog(@"cell separator style: %d separator color: %@", tableView.separatorStyle, tableView.separatorColor); cell.textLabel.text = [marketList objectAtIndex:indexPath.row]; DTCustomColoredAccessory *accessory = [DTCustomColoredAccessory accessoryWithColor:cell.textLabel.textColor]; accessory.highlightedColor = [UIColor darkGrayColor]; cell.accessoryView =accessory; return cell; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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