2012-10-19 3 views
0

나는 objective-c를 xcode에 새로 도입 했으므로 바보 같은 질문에 대해 유감스럽게 생각합니다. 내가하고 싶은 것은 id에 따라 이미지를 UITableView의 셀에로드하는 것이다. xml의 ​​모든 객체는 id와 이미지 이름 id id.jpg를가집니다. 나는 그들을 올바르게로드하기 위해 성취했다. 그러나 내가 이미지를 스크롤하면 사라진다. 내가 dequeueReusableCellWithIdentifier와 관련이있는 것처럼 보인 것으로부터 무엇이 발생했는지는 알 수 있지만 그게 무엇인지 알 수는 없습니다. 여기xcode에서 이미지를로드하는 방법?

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 

    if(cell == nil){ 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; 
    } 

    theList = [app.listArray objectAtIndex:indexPath.row]; 

    NSString *trimmedString = [theList.t_image stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; 

    cell.imageView.image = [UIImage imageNamed:trimmedString]; 
    cell.textLabel.text = theList.t_name; 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

    if(cell.imageView.image == nil){ 
     cell.imageView.image = [UIImage imageNamed:@"untitled.jpg"]; 
    } 

    return cell; 
} 

하고 XML된다 : 어떤 답변

<taxis> 
<taxi> 
<t_id>1</t_id> 
<t_image>1.jpg</t_image> 
<t_name>AAA Taxi</t_name> 
<t_tel>+42014014</t_tel> 
<t_addr>Vodičkova 40</t_addr> 
<t_web>www.radiotaxiaaa.cz</t_web> 
<t_getin>40</t_getin> 
<t_km>26.9</t_km> 
<t_wait>5</t_wait> 
<t_city>Praha</t_city> 
</taxi> 
<taxi> 
<t_id>2</t_id> 
<t_image>2.jpg</t_image> 
<t_name>Modrý anděl</t_name> 
<t_tel>+420737222333</t_tel> 
<t_addr>Cukrovarská 33</t_addr> 
<t_web>www.modryandel.cz</t_web> 
<t_getin>40</t_getin> 
<t_km>19</t_km> 
<t_wait>6</t_wait> 
<t_city>Praha</t_city> 
</taxi> 
</taxis> 

덕분에 저는 여기에 이미지를로드하는 데 사용하고 코드입니다.

+0

IView * vw = [cell.contentView viewWithTag : 99]의 용도는 무엇입니까? if (vw! = nil) { [vw removeFromSuperview]; } –

+0

없음. 이미이 행을 삭제했습니다. 이전에 시도했던 것의 일부였습니다. – adam

+0

모든 행에 그림이 있습니까? –

답변

0

모든 행에 그림이 있습니까? 하지 않으면 것은

if(cell == nil){ 
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; 
} 

UPDATE 후 방법의 beginnign에서 전무로 cell.imageView을 설정해야합니다 : 내가 너라면 배열의 이미지를 캐시 및 cellforrowatindexpath의 method.Try에서이 배열을로드합니다 이것은 아마도 작동합니다 .nil을 NSmutablearray에 객체로 추가 할 수 없으므로 nil 및 UIimage가 아닌 다른 값을 추가해야합니다.

+0

일부 행에 그림이 없습니다. cell.imageView.image = nil;을 추가했습니다. 하지만 여전히 이미지가 사라집니다. – adam

+0

. jpg가 포함 된 xml에 새로운 객체를 작성하면 작업이 원활 해지고 모든 셀에 이미지가 있으므로 자리 표시 자 이미지가 추가 되었기 때문에이 작업을 수행 할 수 있습니다. 모든 도움을 주셔서 감사합니다. 나에게 올바른 길을 보여 줬어. – adam

+0

당신은 환영합니다 –

관련 문제