Array Index in Descending Order - objective-c

I am developing an camera app ,and showing the taken photos in thumbnail view with the numbers .i am displaying the numbers from array index value in ascending order.Like this.In this image numbers are in 1 , 2, 3, i want the numbers in 3 ,2 ,1
Now i want the numbers in descending order.Please help me to do this .my code is ..
NSString *the_index_path = [NSString stringWithFormat:#"%li", (long)indexPath.row+1];
Cell.waterMark_lbl.text = the_index_path;
this is code is in cellforitem at index method in collection view .
Thanks in advance !!!

You can rearrange the data model in reverse order and from there the data will be displayed.
Plan B, more convoluted, it would not change the order. When you have to show the cell 0, display the last, with cell 1 shows the penultimate, etc. You should generate a new indexPath every time you have to show the data.
The other option I understand is that for the first cell you want to show the last number. The operation would be similar, but without generating the new indexPath.
You have to do the subtraction of the total number of elements. Suppose the total number of elements is NUMBER_OF_ELEMENTS
Cell.waterMark_lbl.text = [NSString stringWithFormat:#"%li",NUMBER_OF_ELEMENTS - indexPath.row ]
In the case of reorder the cells without reorder the data, you have to créate a new indexPath and get the data value for display
NSIndexPath *ip = [NSIndePath indexPathForRow:NUMBER_OF_ELEMENTS - indexPath.row inSection:indexPath.section ]
sorry for lexical errors. I have the objective c somewhat forgotten

Related

Convert cell text in progressive number

I have written this SQL in PostgreSQL environment:
SELECT
ST_X("Position4326") AS lon,
ST_Y("Position4326") AS lat,
"Values"[4] AS ppe,
"Values"[5] AS speed,
"Date" AS "timestamp",
"SourceId" AS smartphone,
"Track" as session
FROM
"SingleData"
WHERE
"OsmLineId" = 44792088
AND
array_length("Values", 1) > 4
AND
"Values"[5] > 0
ORDER BY smartphone, session;
Now I have imported the result in Matlab and I have six vectors and one cell (because the text from the UUIDs was converted in cell) all of 5710x1 size.
Now I would like convert the text in the cell, in a progressive number, like 1, 2, 3... for each different session code.
In Excel it is easy with FIND.VERT(obj, matrix, col), but I do not know how do it in Matlab.
Now I have a big cell with a lot of codes like:
ff95465f-0593-43cb-b400-7d32942023e1
I would like convert this cell in an array of numbers where at the first occurrence of
ff95465f-0593-43cb-b400-7d32942023e1 -> 1
and so on. And you put 2 when a different code appear, and so on.
OK, I have solve.
I put the single session code in a second cell C.
At this point, with a for loop, I obtain:
%% Converting of the UUIDs into integer
C = unique(session);
N = length(session);
session2 = zeros(N, 1);
for i = 1:N
session2(i) = find(strcmp(C, session(i)));
end
Thanks to all!

Dataframe non-null values differ from value_counts() values

There is an inconsistency with dataframes that I cant explain. In the following, I'm not looking for a workaround (already found one) but an explanation of what is going on under the hood and how it explains the output.
One of my colleagues which I talked into using python and pandas, has a dataframe "data" with 12,000 rows.
"data" has a column "length" that contains numbers from 0 to 20. she wants to divided the dateframe into groups by length range: 0 to 9 in group 1, 9 to 14 in group 2, 15 and more in group 3. her solution was to add another column, "group", and fill it with the appropriate values. she wrote the following code:
data['group'] = np.nan
mask = data['length'] < 10;
data['group'][mask] = 1;
mask2 = (data['length'] > 9) & (data['phraseLength'] < 15);
data['group'][mask2] = 2;
mask3 = data['length'] > 14;
data['group'][mask3] = 3;
This code is not good, of course. the reason it is not good is because you dont know in run time whether data['group'][mask3], for example, will be a view and thus actually change the dataframe, or it will be a copy and thus the dataframe would remain unchanged. It took me quit sometime to explain it to her, since she argued correctly that she is doing an assignment, not a selection, so the operation should always return a view.
But that was not the strange part. the part the even I couldn't understand is this:
After performing this set of operation, we verified that the assignment took place in two different ways:
By typing data in the console and examining the dataframe summary. It told us we had a few thousand of null values. The number of null values was the same as the size of mask3 so we assumed the last assignment was made on a copy and not on a view.
By typing data.group.value_counts(). That returned 3 values: 1,2 and 3 (surprise) we then typed data.group.value_counts.sum() and it summed up to 12,000!
So by method 2, the group column contained no null values and all the values we wanted it to have. But by method 1 - it didnt!
Can anyone explain this?
see docs here.
You dont' want to set values this way for exactly the reason you pointed; since you don't know if its a view, you don't know that you are actually changing the data. 0.13 will raise/warn that you are attempting to do this, but easiest/best to just access like:
data.loc[mask3,'group'] = 3
which will guarantee you inplace setitem

How to limit maximum number of NSInteger in iOS?

I have a table to show searchData in iOS with UISearchBar.
When i search with keywords, i retrieved data into NSMutableArray.
There is alot of data in NSMutableArray.
I just want to show about 20 datas in tableView.
Normally i used data to show in tableview,
return [self.myArrayData count];
It's show entire data from NSMutableArray.
I want to limit data count to show in tableView.
How can i limit that data count?
Thanks for helping.
NSInteger count = [self.myArrayData count];
if (count > 20) return 20;
return count;

Nsmutablearray insertobject atindex but move down already inserted objects

I wanted to ask if the following scenario is somehow possible to happen.
I have an Nsmutablearray and i have in it 5 objects. I load the Nsmutablearray on an uitableview. I want to insert a new object at the top of the other five objects but also move down all the previously inserted objects down by one. let me give you an example
0 one
1 two
2 three
3 four
4 five
i want to result like this after the new object inserted on the top
0 six
1 one
2 two
3 three
4 four
5 five
Any help appreciated.
- (void)insertObject:(id)anObject atIndex:(NSUInteger)index
This method of NSMutableArray is what you are looking for.
If index is already occupied, the objects at index and beyond are shifted by adding 1 to their indices to make room.
The method you are looking for is: - [NSMutableArray insertObject:atIndex:].
In your example, the index would be 0.

How do I get the section index for a row index in objective-c and UITableView

I want to select a given row in the UTTableView from a index but need to know also the section index.
int localCurrentIndexPath = 9;
NSIndexPath *scrollIndexPath = [NSIndexPath indexPathForRow:localCurrentIndexPath inSection:??];
I need fill in the inSection part. Do I need to supply the inSection value?
Yes. If you only have 1 section, then use 0.