使用唯一项目填充UITableView中的单元格

问题描述:

我有一组URL链接,我尝试将其加载到分组的UITableView中。目标是我有numberOfSectionsInTableView返回[网址计数],所以我可以有部分数量等于url链接的数量。然后在numberOfRowsInSection返回1,所以我只填充每个部分的1个URL。使用唯一项目填充UITableView中的单元格

我遇到的麻烦是确保cellForRowAtIndexPath不会继续抓住第一个url链接。我怀疑这是因为它始终抓取第一个url,因为rowIndex始终为零。

任何想法如何确保我的UITableView中的每个单元格填充不同的url链接?

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
return [newsItems count]; 

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
return 1; 

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

static NSString *MyIdentifier = @"MyIdentifier"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease]; 
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease]; 
    cell.textLabel.lineBreakMode = UILineBreakModeWordWrap; 
    cell.textLabel.numberOfLines = 5; 
} 

// Configure the cell. Get the title of the news item that was parsed out 
int newsItemIndex = [indexPath indexAtPosition: [indexPath length] - 1]; 
[cell.textLabel setText:[[newsItems objectAtIndex: newsItemIndex] objectForKey: @"link"]]; 
return cell; 

}

从我看到这里你是用1行中的每个...林不知道这使得许多部分a您索引正确,你可以做这样的事情

int newsIntemIndex=indexPath.section 

应该为你做的

+0

谢谢Daniel – aahrens 2010-04-13 13:35:29