2014-05-15 23 views
0

我正在使用核心數據,我是obj-c的新手。我試圖將我的核心數據中的「緯度」和「經度」傳遞給mapViewController我無法將數據uitableviewcell傳遞到destinationviewcontroller

代碼:

- (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]; 

} 
} 

和我 「的tableview」 代碼:

-(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; 

} 

當我點擊tableViewCell,我得到這個錯誤:

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

+0

什麼是'Notlar'? – Larme

+0

向我們展示您的'didSelectRowAtIndexpath' – Templar

+0

它看起來像您返回的值fetchedRecordArray不是您的Notlar對象的實例。遍歷代碼,並可能打印出返回的對象,以瞭解它是什麼。可能是零值嗎? –

回答

0

要調用Notlar類型對象中的objectForKey,似乎沒有實現牛逼這種方法,在這裏:

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

你fetchedRecordsArray包含Notlar對象,而不是字典,這就是爲什麼你不能調用此方法。

沒有更多的信息,我不能告訴你如何準確解決它,但有兩種可能性:要麼你Notlar對象包含一個緯度和經度屬性,你只需要做到:

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

,或者你應該訪問的字典與lon和lat兩個參數值,而不是在其他地方你fetchedRecordsArray一個陣列。

+0

thx work perfect – SeRcCaN

+0

不客氣。如果它對你有用,你應該考慮接受我的答案是正確的(答案投票計數下的複選標記)。 – Garoal

相關問題