2013-05-31 44 views
0

我想在我的單元格中顯示圖像,但前提是JSON數據的值爲1(只有0或1可能) 也許如果JSON數據的值爲0顯示不同的圖像,所以每個細胞可以顯示2個不同的圖像。
到目前爲止的問題是,單元格包含圖像,而不是數據的值是什麼JSON數據是。if語句在單元格中顯示圖像

到目前爲止的代碼:

NSArray *arrayOfEntry = [allDataDictionary objectForKey:@"notities"]; 
for (NSDictionary *diction in arrayOfEntry) 
{ 
    sonResults = [allDataDictionary objectForKey:@"notities"]; 
    NSMutableString *checkvink = [diction objectForKey:@"not_verwerkt"]; 

    if(![checkvink isEqual: @"1"]) 
    { 
      NSString *path = [[NSBundle mainBundle] pathForResource:@"vink" ofType:@"png"]; 
      imageData = [NSData dataWithData:[NSData dataWithContentsOfFile:path]]; 
    } 
}  

然後我告訴像這樣

UIImage *imageLoad = [[UIImage alloc] initWithData:imageData]; 
cell.notAfbeel.image = imageLoad; 

像我在做什麼錯?

編輯:完整的cellForRowAtIndexPath

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
     static NSString *Cellidentifier = @"Cell"; 

NotitieCell *cell = [tableView dequeueReusableCellWithIdentifier:Cellidentifier]; 

if(!cell) 
{ 
    cell = [[NotitieCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cellidentifier]; 
} 

NSDictionary *appsdict = [jsonResults objectAtIndex:indexPath.row]; 

UIImage *imageLoad = [[UIImage alloc] initWithData:imageData]; 

cell.notAfbeel.image = imageLoad; 

return cell; 
} 

JSON數據

{ 
"notities": [{ 
    "not_nr": "1191555", 
    "not_tijd": "12:29:54", 
    "not_type": "0", 
    "not_behandeld": "Richard", 
    "not_bestemd": "Richard", 
    "not_contactpers": "Maarten", 
    "not_prioriteit": "1", 
    "not_onderwerp": "Printer staat er nog steeds in", 
    "not_naam": "apple store", 
    "not_woonpl": "Amsterdam", 
    "not_land": "NL", 
    "not_verwerkt": "0" 
    } 
} 
+0

發表您的整個的cellForRowAtIndexPath方法 –

+0

發佈的cellForRowAtIndexPath – SpeedfreakR

+0

只是語句之前分配的imageData中的cellForRowAtIndexPath本身 「的UIImage * imageLoad = [[UIImage的頁頭] initWithData:爲imageData]。」 對不起延遲夥計 –

回答

0

問題是imageData是一個實例變量。您正在爲整個對象實例設置其值,而不僅僅是單元格。所以,她調用了cellForRowAtIndexPath,它將這個變量值放在所有單元格中。

轉變你的arrayOfEntry在屬性並假設它完全在你的tableView顯示,我們可以把您的cellForRowAtIndexPath這樣的:

也許它不是根據數據的最佳答案,但僅僅是給你一個想法,讓你可以適應它。

+0

謝謝你這裏面爲我工作!對不起已故的響應(流感有我)。我刪除了自己。因爲我已經說前面的代碼。 – SpeedfreakR

0

也許你應該使用isEqualToString代替isEqual,因爲你在該行比較的NSString值:

if(![checkvink isEqualToString: @"1"]) 
+0

難以忍受的伎倆 – SpeedfreakR

+0

哼哼......你可以發佈你的JSON文件的一部分@SpeedfreakR嗎?也許這將有助於有點 –

+0

JSON是沒有問題的(我猜是因爲我可以證明與JSON數據標籤,但我會張貼。 – SpeedfreakR