【问题标题】:Populating cell in UITableView with unique items使用唯一项填充 UITableView 中的单元格
【发布时间】:2010-04-13 21:26:42
【问题描述】:

我有一组 URL 链接,我正试图将它们加载到 Grouped UITableView 中。目标是我有 numberOfSectionsInTableView return [url count] 所以我可以让部分的数量等于 url 链接的数量。然后在 numberOfRowsInSection 中返回 1,所以我只为每个部分填充 1 个 URL。

我遇到的麻烦是确保 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;

}

【问题讨论】:

    标签: iphone uitableview


    【解决方案1】:

    从我在这里看到的情况来看,您正在制作许多部分,每个部分有 1 行...我不确定您是否正确获取索引,您可以执行类似的操作

    int newsIntemIndex=indexPath.section 
    

    应该为你做的

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-28
      • 1970-01-01
      • 1970-01-01
      • 2012-05-06
      • 1970-01-01
      • 1970-01-01
      • 2021-07-11
      • 1970-01-01
      相关资源
      最近更新 更多