2011-09-29 65 views
0

我在每個單元格中都有一個包含聖經經文的tableview單元格,我需要的是當用戶點擊單元格時,我必須將字符串中的單元格中的詩句取出。這是爲了共享功能。 請幫幫我。如何獲取tableview單元格中的值

+0

你如何創建單元格並放在那裏? – Nekto

+0

我想用一個數組來做這個儀式? – booleanBoy

+0

@booleanBoy我使用數組來存儲經文。 – ICoder

回答

0

要添加的詩句,你可能使用

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

從抽頭細胞得到的詩句回來,你使用

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

在填充的tableView,你用indexPath得到正確的詩歌 - 這就是你想要再次做的事情。假設你有一個NSArray稱爲「詩」:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSString *verse = [verses objectAtIndex:indexPath.row]; 
    NSLog(@"The selected verse is: %@",verse); 
} 
+0

但有超過3000個詩句,如何爲此編寫代碼。? – ICoder

+0

就像用詩句填充單元格一樣。我想你有一個「NSArray」的詩句,不是嗎? – tilo

+0

我有nsarray的詩句 – ICoder

0

如果詩已經是一個標準的UITableViewCell,您可以通過UITableViewCell的屬性來訪問它,像cell.textLabel.text或cell.detailTextLabel.text。檢查UITableViewCell類的引用。

0

使用相同的數組,以獲得弦.... 在didSelectRowAtIndexPath方法委託

有這樣

的NSLog碼(@ 「%@」,[的NSString stringWithFormat: 「%@」, [yourArray ObjectAtIndex:indexPath.row]);

您還可以使用上面的代碼來獲取NSString變量中的字符串。

相關問題