请查看以下代码,它也支持方向
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"CountryCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
// NSString *continent = [[self.countries allKeys] objectAtIndex:indexPath.row];
NSString *continent1 = [self tableView:tableView titleForHeaderInSection:indexPath.section];
NSLog(@"Contine............%@", continent1);
int k = [[self.countries valueForKey:continent1] count];
UIScrollView *previewScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, cell.contentView.frame.size.width, 250)];
previewScrollView.backgroundColor = [UIColor clearColor];
previewScrollView.pagingEnabled = TRUE;
previewScrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[previewScrollView setContentSize:CGSizeMake(250*k, 60.0)];
previewScrollView.showsHorizontalScrollIndicator = YES;
NSLog(@"cell.contentView.frame.size.widt %f",cell.contentView.frame.size.width);
NSLog(@"K %@ %d",continent1, k);
for(int i=0 ; i<k; i++ ){
imageView.image = [UIImage imageNamed:[[self.countries valueForKey:continent1] objectAtIndex:i]];
imageView.contentMode = UIViewContentModeCenter;
[previewScrollView addSubview:imageView];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(250.0*i, 10, 200, 250);
NSLog(@"%@", [NSString stringWithFormat:@"%d%d",indexPath.section,i]);
btn.tag = [[NSString stringWithFormat:@"%d%d",indexPath.section,i] intValue];
[btn addTarget:self action:@selector(btnTapped:) forControlEvents:UIControlEventTouchDown];
[previewScrollView addSubview:btn];
}
[[cell contentView] insertSubview:previewScrollView atIndex:0];
// [cell addSubview:previewScrollView];
}
return cell;
}