2015-09-24 77 views
1

我得到的錯誤,當我像關於表視圖細胞indexpath.row

profileJson = dicData[@"profile"][0]; 

cell.userName.text = [[profileJson objectForKey:@"First_Name"] objectAtIndex:indexPath.row]; 

Error: [__NSCFString objectAtIndex:]: unrecognized selector sent to instance 0x7fe5915d7180

如果我寫這篇文章的語句

cell.userName.text = [profileJson objectForKey:@"First_Name"]; 

的最後一個值是越來越值分配到小區分配。如果count是3,那麼輸出看起來是這樣的:

Teja公司

Teja公司

Teja公司

對於每一個細胞。

+0

後從你的'的cellForRowAtIndexPath代碼:'方法。 –

+0

它有很多數據,我不能在這裏發佈。 –

+0

真的很高興在這裏看到我的名字! :P你確定這[profileJson objectForKey:@「First_Name」]返回一個數組? –

回答

0

這在你的 「的cellForRowAtIndexPath:」 法

NSDictionary *profileJson = dicData[@"profile"][indexPath.row]; 

NSString *userNameString = [profileJson objectForKey:@"First_Name"]; 

cell.userName.text = userNameString; 
+0

非常感謝你,這爲我工作。 –

2

你似乎是不匹配你的代碼詢問從JSON解包的數據結構,您還沒有它,但它似乎像你需要:

profileJson = dicData[@"profile"][indexPath.row]; 

cell.userName.text = [profileJson objectForKey:@"First_Name"]; 

所以你索引到profiles數組基於你的表索引,而不是總是採取第一個,然後提取第一個名稱變量(以前你對數組和字符串感到困惑)。

+0

ProfileJson是來自解析器的dictionary.which。 如何將它指定給單元格 –

+0

除非您創建了一個接受它並處理它的單元格子類,否則您不能指定字典,否則您需要解壓縮字典以獲取字符串,例如我的答案 – Wain

+0

。 –