2015-11-14 18 views
-1

我需要獲取選定行的部分數據(cell.textLabel.text)。問題是這是什麼在單元格(根據調試器),我無法弄清楚如何去它。這是代碼-didSelectRowAtIndexPath如何獲取UITableView的單元格數據?

NSString *cellText = selectedCell.textLabel.text; 

行,這是什麼在selectedCell.textLabel.text

enter image description here

對於我的生活,我想不出如何獲得3部分中的第1部分。

任何想法/意見/答案將不勝感激!

+3

你不應該在任何時候需要獲取數據了看法。你的觀點是顯示數據不存儲它。如果你想在那個視圖中獲取文本,那麼只需轉到你首先用來填充它的數據(或其他)。 – Fogmeister

+0

你不明白這個問題;我同意你的看法,但有時候必須使用非常規方法來解決問題。感謝您評論'SD – SpokaneDude

+0

你是如何創建和配置你的單元格? IOW,你的'tableView:cellForRowAtIndexPath:'方法是什麼樣的? – Avi

回答

0

我明白了;這是代碼:

- (void) tableView:(UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath { 

if(isFiltered) { 
    Books *su = filteredTableData[indexPath.row]; 
    passedSKU = su.sku; 
} 
else { 
    // get the key from the cell that was selected from the list 
    Books *selectedBook = [booksArray objectAtIndex:indexPath.row]; 
    passedSKU = selectedBook.sku; 
} 

// programmatically set the tabBar index 
[self.tabBarController setSelectedIndex: 1]; 

}

1

你有沒有試過類似的東西?

NSString *cellText = selectedCell.textLabel.text; 
NSArray *components = [cellText componentsSeparatedByString:@" "]; 
if (components.count > 0) { 
    NSString *firstPart = components[0]; 
    NSLog(@"%@", firstPart); 
} 
+0

有趣...沒有任何東西進入* cellText *,我不知道爲什麼,因爲* selectedCell.textLabel.text *有一個值。謝謝你的努力...我很感激。 SD – SpokaneDude

相關問題