我很新的xcode na objective-c所以我很抱歉愚蠢的問題。我想要做的是根據id將圖像加載到UITableView中的單元格。 xml中的每個對象都有id和圖像名稱id id.jpg。我完成了加載它們,但當我滾動圖像消失。從我發現它看起來它與dequeueReusableCellWithIdentifier有關,但我無法弄清楚它是什麼。下面是我使用加載圖像的代碼:xcode - 如何從正確的方式從XML加載圖像?
-(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>
感謝您的任何答覆。
IView * vw = [cell.contentView viewWithTag:99]的目的是什麼? (vw!= nil){ [vw removeFromSuperview]; } –
無。我已經刪除了這一行。這是我以前嘗試的一部分。 – adam
做所有的行都有圖片嗎? –