Reputation: 93
I have a dynamic array. I need to display tableview as following scenario... In the First cell i need to display 1 item. In the second cell i need to display 2 items. In the third cell i need to display 3 items. In the forth cell i need to display 1 item. In the fifth cell i need to display 2 items. In the sixth cell i need to display 3 items. and so on... Could any one please suggest how to return no of rows in a section.
Upvotes: 1
Views: 150
Reputation: 2910
A faster method might be:
Notice in the divide by 2 method, most numbers work. The ones don't work are: 2, 4, 8, 10... basically, even numbers that aren't divisible by 6.
So we can come up with something like:
int count = array.count;
if (count % 2 == 0 && count % 6 != 0) {
count + 2;
}
int rows = ceilf(count / 2);
Or we can write a for loop:
int counter = array.size;
int rows = 0;
int dec = 1;
while (counter > 0) {
rows++;
counter - dec;
dec = dec % 3 + 1;
}
The for loop is of course, slower.
Upvotes: 1
Reputation: 14128
Simple logic for this is:
NoOfRows = TotalCount / 2
For e.g.:
If last value is 6 then, total no of rows are (6 / 2) = 3
If last value is 12 then, total no of rows are (12 / 2) = 6
You have to think logical that's it.
Hope this helps.
Upvotes: 1