0

我正在将 RSS 解析为 UITableview,数据看起来应该是这样,但是当我选择 UITableview 中的一个字段时,它会打开不同的数据,然后是它应该打开的数据。此外,当我滚动表格视图时,我选择的同一字段再次给出不同的数据。

那么请问我在哪里犯了我的错误?

RSS 链接:http ://www.luaikalkatawi.me/picksound

从现在开始感谢。

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

    NSString *trimed = [[containerObject.track init] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

    NSLog(@"The link is %@", trimed);
}

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

ImgCell *cell = (ImgCell*)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];

if (cell == nil)
{
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:cellIdentifier owner:nil options:nil];
    cell = (ImgCell*)[nib objectAtIndex:0];
}

containerObject = [objectCollection objectAtIndex:indexPath.row];//use the common object again for holding the corresponding array object

///// Image reloading from HJCacheClasses
[cell.img clear];
NSString *str1 = containerObject.image; //we use image property of rss object to set the image
NSString *trimmedString = [str1 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSURL *url = [NSURL URLWithString:trimmedString];
cell.img.url = url; //set the url to img view
[self.imgMan manage:cell.img];

cell.mainText.text = containerObject.title; //title member variable for setting title
cell.detailText.text = containerObject.description;//desc variable foe
return cell;
}
4

1 回答 1

0

我不知道为什么这会让你感到困惑,但正确的 containerObject 应该在 didSelectRowAtIndexPath 中访问。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    containerObject = [objectCollection objectAtIndex:indexPath.row];
    NSString *trimed = [[containerObject.track init] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

    NSLog(@"The link is %@", trimed);
}
于 2012-12-06T18:28:48.760 回答