Populating cell in UITableView with unique items
Posted
by aahrens
on Stack Overflow
See other posts from Stack Overflow
or by aahrens
Published on 2010-04-13T13:21:24Z
Indexed on
2010/04/13
13:22 UTC
Read the original article
Hit count: 410
I have an array of URL Links that I'm trying to load into a Grouped UITableView. The goal being that I have numberOfSectionsInTableView return [url count] so I can have number of sections equal to the number of url links. Then in numberOfRowsInSection returns 1 so I only populate 1 URL for each section.
The trouble I'm having is to ensure that cellForRowAtIndexPath won't keep grabbing the first url link. I suspect it's because it's always grabbing the first url because the rowIndex is always zero.
Any ideas how to ensure that each cell in my UITableView is populated with a different url link?
- (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;
}
© Stack Overflow or respective owner