objective c get first row in uitableview - objective-c

how do i determine the top row in my uitableview that is currently visible? The table has 200+ rows so when a row is clicked i want to determine the first row number that is currently visible. The idea is that when i go to a detail view page for the table item and come back to the page i can scroll my table exactly to that row ( also my table is all in 1 section if that helps) any help much appreciated

UITableView has a visibleCells method. Check out the documentation. If it's more useful to you, there's also indexPathsForVisibleRows.

Related

How to scroll PyGTK ScrolledWindow to a certain row of a nested table?

I have a program in PyGTK which has a ScrolledWindow and a Table nested in it. The table rows can be of a different height. What I'm trying to find is a way to scroll the view so it begins from the selected row. I know how to move the scrollbar to a certain position using the scrolled_window.get_vadjustment().set_value(), but I do not know how to find the scroll position of the table rows.
Alternatively, maybe I'm using wrong widget and someone can point me to the right one? I'm trying to achieve the following behaviour: the screen shows the rows of a table, the top row is the currently selected object, when the user presses up or down buttons, the whole table scrolls down or up, so the previous or the next row becomes the top row.
Nevermind, I found a solution: you have to use the child widget get_allocation() function, which returns the bounding rectangle of a child widget relative to the scrolledwindow, so child.get_allocation().y is the answer to my own question.

Disable autoscroll top on insertRowBefore in a TableView in Appcelerator/Titanium

i'm currently using a TableView to display some elements in Appcelerator/Titanium.
The problem that i have is that when i make a pull to refresh and i call the method "insertRowBefore" to insert new elements at the beginning of the table using the method like following:
$.table.insertRowBefore(0,row);
The table auto scrolls to top, and it looks a little bit bad when there're a lot rows to insert, i want to keep the current position.
Any ideas?
I have had the same problem it looks very ugly when inserting rows at table's top. I have managed this strange behavior by not inserting rows in table directly but inserting them to an array first :
//i suppose that you have an initial array contain your old rows oldRows
//add rows in the top
for(int i=0;i<7;i++)
oldRows.unshift(newRows[i]);
then set table's data
$.table.setData(oldRows);

How to prevent only one row to be ordered-obj c

I have a table view. And I have multiple rows. While doing the reorder in editing mode, I want one row to stay in the first index all the time. So, if a user wants to swap a row with the first row, it shouldnt allow it. But it should be possible between the second and the third row.
How can I do this?
Thank you very much in advance
Set the first table view cell's showsReorderControl to NO and return NO in tableView:canMoveRowAtIndexPath: for the first row.
You can also implement the UITableViewDelegate method tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath:
Here you can return an alternate index path if the proposed one is (0, 0).
Return Value
An index-path object locating the desired row destination
for the move operation. Return proposedDestinationIndexPath if that
location is suitable.
Discussion
This method allows customization of the target row for a
particular row as it is being moved up and down a table view. As the
dragged row hovers over a another row, the destination row slides
downward to visually make room for the relocation; this is the
location identified by proposedDestinationIndexPath.

Objective C: How to highlight a tableView Cell and keep it highlighted when table is reloaded?

Really need some advice for this. I am trying to do a couple of things.
1) Set the first cell of the table view to be highlighted the first time the table is loaded. The user can then proceed to select/highlight other cells in the table. How can I highlight the cell for the very first time?
2) After some changes are made to the values in a row, I will reload the table data, however this will remove the highlight on the cell. Is there any way to keep the cell highlighted even after table reload.
Thanks!
Zhen
Try selectRowAtIndexPath:animated:scrollPosition:

How t add new rows atomatically, on scrolling the table view

I want to make an application in which I need a functionality of automatic addition on new rows to the table view. say at first the table view has 5 rows in it, after that when I scroll the table then more 5 rows should be added to the end of the table.
please help me!!!!
Hey!! You can try the idea as implemented on following post
http://iphoneappmonster.blogspot.com/2011/04/insert-rows-to-table-view-on-click-of.html
The way you would do this is to implement tableView:willDisplayCell:forRowAtIndexPath in your UITableViewDelegate, and watch for the last row being displayed (using the indexPath argument).
When the last row is about to be displayed, set a flag and call -reloadData on your UITableView. This will force the table view's recalculation, and call your datasource where you should see the flag and add (say) 5 rows to the previous total number of rows (and also clear the flag).
Now, the row that will display will no longer be the last row (it will have 5 rows below it) and presto! Infinitely-scrolling table view.
Keeping track of the total number of rows (and their content) is left as an exercise for the reader.