开发者

Populating cell in UITableView with unique items

开发者 https://www.devze.com 2022-12-26 21:32 出处:网络
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 th

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 (开发者_如何学Gocell == 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;

}


From what i see here you are making many sections with 1 row each...im not sure that ayou are getting the index correctly you can do something like this

int newsIntemIndex=indexPath.section 

that should do it for you

0

精彩评论

暂无评论...
验证码 换一张
取 消