The data didn't show up after calling 'deleteRow' method - uitableview

The problem like this in this gif picture, when I called 'deleteRow'
method the other row which should show some data became blank, I did nothing to that row,this picture show what I do here:
(forgive my poor english 😓)
I wanna know why this row been refreshed after I update the table view.

Related

Getting the data of all TableView Cell which all has TextFields in it (including the hidden views)

I'd like to get every data that is within all cells in one tableview which is quite a long list.
I'm looking for an approach on how to retrieve everything including those hidden in view, which I know the views are reused. I think some of you might have experienced this problem before, what are your approach on this?
I've tried
let cells = self.tableView.visibleCells
then looping into every cell and saving each data to an array but it is not effective in getting those that aren't part of the view or hidden. Is there a way to get over this?
In cellForRowAtIndexPath, YOU are telling the table what is in each cell. So why would you turn around and ask the table what's in each cell? If the user puts "Hello" in your first cell, then scrolls the table enough to push that first cell out of view, then when the user scrolls back to the top, YOU are the one telling it to put "Hello" back in that first cell. YOU own the data source, not the table.
You need a data source. That can be "empty" at first, maybe an array of empty strings if that's what you want (each index in the array could map to a table row for example). But then, as the user interacts with the text fields in the cells, you need to update that data source with the text they entered.
You should use that data source as your source for the cellForRowAtIndex method. That way you can handle populating the cells when they are requested by the table, and you also know all the data when the user is done.
Why not just update the model each time the user taps a key when editing a textfield? You could create a protocol for that cell subclass and make your view controller the delegate for each cell. As long as cells are guaranteed to stay on the screen while you're typing (you'll get some weird behaviors if not) the cell can send a message to the view controller or whatever you hook it up to telling it what new value to store. Then everything is already stored for you when you need the full list, and you don't have to interact with the tableview.

How get facebook like "New stories" Button iOS?

I want the similar function that facebook app use to load new post feeds in their app, It works like they check for feed update every few minutes and if their are new feed are available then there will be a button will appear on top of Table view named new feed and when it tapped it will load all new feed cell one by one with animation not not reloading complete table. I just want some guidance any help will be appreciated
Edit:
What I have now is
A UITableView which loads feed from the server when first loads and there is also pull to refresh control their.
What I have to do now is.
Put a timer to check feed changes( easy to do no problem with that)
load new table view cell on top without making any changes on the
screen except the new feed button.
On tap of button scroll up to show all new cell.

Swift code to loop through the table custom cell rows

I am looking for code in swift to loop through the table custom cell row (have 2 text boxes in row). These rows are dynamically created and on click of button, i want to read those text box values. I don't find good example for this in online, any help is appreciated.
Your thinking is wrong. You should not store any data in table view cells. The user can scroll them off the screen at any time and any changes to the data is lost.
You should really store the input from your table view cells into your model as soon as the user makes a change.

How to tell if a sqlite table view is empty?

I have a working RSS feed reader using SQLite 3 for the iPhone that I have submitted to apple for review. What I am wandering is wether is there a way to tell if a sqlite table view is empty. I have read about doing this, but I can't seem to find one for using SQLite. I want this because when the user first opens the app, the item view controller is empty until they refresh the table by pulling down. Is there a way to add a label that says something like, "Please refresh", but only when the table is empty?
select count(*) from some_table;
If that returns 0 then the table is empty. Of course if you already have a query against a table that returns all rows and you get back zero rows then you know the table is empty.
If you know there is an empty table then setup your table view's data source with 1 row that displays your "please refresh" message.
But if there is no data, what is the point of refreshing? And if the user can refresh, then why not do it automatically for the user? Why make the user do the refresh?
On your viewDidLoad method, you must get all the feed from sqlite... so start a loading view on viewDidLoad.. and remove that view when you get all the views.... then you could check your list of items for count and when the count == 0, display what ever message you want to display.

Where should I put the logic to get the record from Database?

I have two buttons on a action sheet, when I click one of the button, it will display all the students record in another view. All these records need to be retrieved from DB. Currently I put the logic of retrieve the record in the viewwillAppear method, But after I click the button the screen froze there for a few seconds then the student list will displayed.
Per my understanding my logic of retrieve the record was in viewWillAppear method in student list view. After I click the button , it should to directly to student list view , then in the student list view it will try to load the data. But now after I click the button why it froze in the action sheet? Or are there any other place that I can put the load record logic in so that it will not froze in the previous action sheet After I clicked the button.
If you're going to post to SO, you always should include your existing code. I'd suggest you update your question accordingly. See the FAQ.
When you say that it "froze", do I infer that you're saying that there was a delay before you saw your new view with the data, but that it eventually appeared? If so your task is how to identify where the delay took place. So, I'd suggest you start inserting NSLog statements in the various methods so you can identify where exactly the delay is taking place. Did it take a long time for the new view to be loaded? For the data to be retrieved? Etc. Until you narrow down the problem, identify the source of the delay, you won't be able to solve it. You need to develop the skills to diagnose and troubleshoot your problems. By the way, if you're still having problems figuring out how to diagnose your code and the NSLog doesn't help, you can also refer to Apple's documentation on debugging and stepping through your code. You should only post here after you've narrowed down precisely where in your code the problem is manifesting itself.
Third, most people load their data for their new views in viewDidLoad, not viewWillAppear; if you ever went to a subview of your student list view and then came back to your student list (i.e. the student list view reappeared, i.e. viewWillAppear will trigger again), would you really want to load the data again, even though you've already loaded it? Probably not. I know you might not have another view that you're loading after you load your student list view, but you may eventually (e.g., a student detail view), so good practice is that you should load your view's data in viewDidLoad (which will trigger only the first time the view is initially loaded).

Resources