سؤال

I'm using core data and I'm a rookie for the obj-c. I'm trying to pass "latitude" and "longitude" in my core data to mapViewController.

Code:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"ShowMap"]) {

    HaritaVC *destViewController = segue.destinationViewController;        
    NSIndexPath *path = [self.myTableView indexPathForSelectedRow];
    NSString *lattoPass = [NSString stringWithString:[[self.fetchedRecordsArray objectAtIndex:path.row]objectForKey:@"lat"]];
    NSString *lontoPass = [NSString stringWithString:[[self.fetchedRecordsArray objectAtIndex:path.row]objectForKey:@"lon"]];

    destViewController.latt = [[NSString alloc] initWithFormat:@"%@",lattoPass];
    destViewController.lonn = [[NSString alloc] initWithFormat:@"%@",lontoPass];

}
}

and my "tableview" code:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

static NSString *CellIdentifier = @"MainCell";
CellDetail *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
Notlar * notlar = [self.fetchedRecordsArray objectAtIndex:indexPath.row];
cell.titleLabel.text = [NSString stringWithFormat:@"%@ %@, %@ ",notlar.bilgi,notlar.notlar,notlar.tarih];

return cell;

}

when I click to tableViewCell, i get this error:

'NSInvalidArgumentException', reason: '-[Notlar objectForKey:]: unrecognized selector sent to instance 0x1aa56b60'

هل كانت مفيدة؟

المحلول

You are calling objectForKey in a Notlar type object, which doesn't seem to implement this method, here:

 NSString *lattoPass = [NSString stringWithString:[[self.fetchedRecordsArray objectAtIndex:path.row]objectForKey:@"lat"]];
NSString *lontoPass = [NSString stringWithString:[[self.fetchedRecordsArray objectAtIndex:path.row]objectForKey:@"lon"]];

Your fetchedRecordsArray contains Notlar objects, not dictionaries, and that's why you can't call this method.

Without more information, I'm not able to tell you how to solve it exactly, but there are two possibilities: either your Notlar object contains a lat and a lon property, and you only need to do:

NSString *lattoPass = [NSString stringWithString:[(Notlar *)[self.fetchedRecordsArray objectAtIndex:path.row] lat];
NSString *lontoPass = [NSString stringWithString:[(Notlar *)[self.fetchedRecordsArray objectAtIndex:path.row] lon];

or you should be accessing a array of dictionaries with lon and lat values elsewhere instead your fetchedRecordsArray.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top