【发布时间】: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