Buttons in table view cells cause unwanted scrolling - swift

I have a button in my table view cell so that a user can like a post. Whenever I click the button, the table view scolls a couple cells up. I do not want this scrolling to occur. I also do not have paging enabled so I do not know why this is happening. Does anyone know how I can prevent this? Thanks.

Suppose you have liked on the 3rd row of the UITableView then simple call line like this
first update your array then call
self.tableView.reloadRowsAtIndexPaths([/*yourindexpath*/],
withRowAnimation: UITableViewRowAnimation.Fade)

Related

Closing UITableViewController when the keyboard covers cells causes crash

I have a UITableViewController with custom cells for static and editable text. Standard stuff, nothing fancy.
The cell data is stored so that when cells are reused, the data is placed back inside them.
The problem is this: when the user has the cursor in a UITextField cell and the keyboard's up, the keyboard is covering three rows in the table view. There's a cancel button at the top of the view controller which is supposed to dismiss the view controller. When I call dismissModalViewController, the keyboard hides, but the UITableViewController wants to refresh the rows that were under the keyboard while the view's going away. However, the view's already in its death throes and I get a crash because the table view's trying to call cellForRowAtIndexPath to update rows that are in the process of being removed.
I tried waiting for the keyboard to hide. No good.
I tried resigning the first responder so the keyboard goes away and updates the rows first before dismissing the view controller, but there's nothing I can find that tells me the data's finished updating.
What I need is some event that tells me that the table is finished updating, or tell the table view to not ask for data from the delegate, or tell the table view to not update when the keyboard is going away.
Or there's something simple I'm missing.
Any help?
If you have not more cells, i advice you to make a different Reusable Identifier for each cell.That very better to save the state of cells after being dequeued
I solved my own problem. Inside cellForRowAtIndexPath, I was setting text inside a UITextField for pointers that may no longer exist. What I did to fix the problem was still create the cell, but before setting the text inside it, I checked if the Cancel button was pressed and if it was, return the empty cell.
I was hoping there'd be a better solution such as waiting for the cells to finish updating, but that doesn't seem to be happening.

reloadData causes first cell to disappear in UITableView

This is a stab in the dark that someone would know what is going on here, but i have a UITableView that the user is allowed to reorder. Upon reordering cells I reload the UITableview data (because I change each cells label based upon its order in the table).
[self.tableView reloadData]
However, when i reorder the first cell with any other, everything acts as its supposed to and i get no errors but the first cell disappears. If i reorder any other cells in the tableview everything is fine

Show selected row always while scrolling UITableView?

Let's say we have a UITableView with some 100 rows, we select a row and after that we scroll the UITableView. The selected row is also scrolled top or bottom direction but I want the selected row to be always visible to the user while scrolling the table. Is it possible ?? please help me out which sample code..(it is same like twitter scrolling)
If you want this, you'll have to write a completely custom tableview from scratch (which I believe was done for Twitter.app). There's no way to do that with the built-in tableview.

Delete cells in table view Iphone with edit button

I have a table view with different cells and basically I would like an edit button which would then make those red circle appear in each cell and be able to delete them. I already know how to make the "Edit" button appear and also I have overridden the commitEditingStyle method for the table view so I would like to know how to link the button to the action which trigers the red circle and how to make them appear and finally how to actually delete the cells thankyou :)
The editing style on your table view cells should be set to UITableViewCellEditingStyleDelete, and then you just need to make sure to call setEditing:animated: on your table view. UITableViewController can help provide a lot of this functionality pre-baked.
That's actually done through an undocumented API (though I'm not quite sure why) - using it would probably get your app rejected.
However, lots of apps simulate this functionality with their own code - you'd basically define a custom UITableViewCell subclass which changed its background color / toggled that extra red circle image when tapped, keep track of which cells had been tapped, and finally delete them all by calling deleteRowsAtIndexPaths: on the table with the collected list of rows.

iPHONE SDK - tableview, remembering how much it is scrolled?

i was wondering how do i do this?
I wish to make a tableview configured in a way that if i scroll down a tableview and click on one row, i will be brought to another view. But when i click a back button of some sort. i return to the tableview but still viewing that particular row. kinda like the iPod table in the iPhone? Remembering scrolled position?
i just want to know how to do the 'remembering scrolled position' part.
Save your index path in tableView:didSelectCellAtIndexPath: before pushing the new view, use it later. This will give you the NSIndexPath pointing at the cell that was selected by the user, not necessarily give you the same position it was at before they tapped the item. So keep that in mind.
Continue from jer's answer. You can use indexPath when calling this method in tableView:
UITableView selectRowAtIndexPath:animated:scrollPosition: