Reputation: 4383
I want to display N number of button on single cell of tableview. for that i have created xib of one button and i want to load that xib N number of times into my tableview cell.
I use following code but it just display xib one time in every row. I have used for loop and scrollview to have multiple view of xib one single row but it only display one time.
Update :- I change my table vie code as suggested in answer. but my scrollview is not working horizontally and i got extra xib view at starting of every row.
I think this is beacuse of [self.table registerNib:[UINib nibWithNibName:@"wagon" bundle:nil] forCellReuseIdentifier:@"Cell"];
in view did load..how can i solve this problem?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell==nil) {
}
cellScrollViewClass * scrollView = [[cellScrollViewClass alloc] initWithFrame:CGRectMake(MyPadding,14,myWidth-MyPadding*2,200)]; // Scrollview
scrollView.scrollEnabled=YES;
scrollView.userInteractionEnabled=YES;
scrollView.showsHorizontalScrollIndicator=NO;
scrollView.contentSize = CGSizeMake((336*NumberofCell),187); // To make ContentSize for item to scroll
for (int i = 0; i < NumberofCell; i++)
{ // for loop to add 2 wagon view and 1 engine view on Left hand side Custom cell.
UIView *nib = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
UIView *wagonView = [[UIView alloc]initWithFrame:CGRectMake((385*i)-200, 18, 385, 163)];
[wagonView addSubview:nib];
[scrollView addSubview:wagonView];
}
cell.accessoryView=scrollView;
return cell;
}
In view did load i register nib
[[self table]setDelegate:self];
[[self table]setDataSource:self];
[self.view addSubview:table];
[table setShowsHorizontalScrollIndicator:NO];
[table setShowsVerticalScrollIndicator:NO];
table.separatorColor = [UIColor clearColor];
[table setContentInset:UIEdgeInsetsMake(-15,0,0,0)];
[self.table registerNib:[UINib nibWithNibName:@"wagon" bundle:nil] forCellReuseIdentifier:@"Cell"];
Upvotes: 1
Views: 1377
Reputation: 1099
move your code outside if (cell==nil){}
. This condition will return YES only if it fails to dequeue.
Upvotes: 2
Reputation: 357
Create one (Main) UIView which you add all wagonView to, after the loop add the "Main" view to the Scrollview.
Upvotes: 1