Vote count:
0
I am trying to populate a table with rows of buttons dynamically. When the table is launched, I pass it an array containing the correct buttons. The quantity of buttons, and thus rows, will vary. This works, until I need to create a new row (i.e. too many buttons to fit on the first row). Let's assume I limit it to 4 buttons per row. Then my buttons start on row 2, not row 1 like they should. They also get clipped on the right bounds.
Related code from numberOfRowsInSection
if ([[self fileTypeButtonsArray] count] % 4)
return ([[self fileTypeButtonsArray] count] / 4) + 1;
else
return [[self fileTypeButtonsArray] count] / 4;
Related code from cellForRowAtIndexPath:
for (int i = 0; i < [self.fileTypeButtonsArray count]; i++)
{
UIButton *currentButton = (UIButton *)[self.fileTypeButtonsArray objectAtIndex:i];
[currentButton setTag:i];
[currentButton setFrame:CGRectMake((kButtonPadding + (i * (kButtonWidth + kButtonPadding))), kButtonPadding, kButtonWidth, kButtonHeight)];
[defaultCell.contentView addSubview:currentButton];
}
Example Buttons exceeding 1 row - bad
Example Buttons fit on 1 row - good
I realize I'm just telling it to keep adding buttons to the right of each other. I'm stumped how I tell it which rows to put them in. Also stumped why they start in the second row (index 1), instead of top row (index 0). Thanks for any assistance.
Adding Array of Buttons to Appropriate Table Rows
Aucun commentaire:
Enregistrer un commentaire