Dynamically add and delete a row from table & maintain hierarchy of table - iphone

In my table I m filling the rows using an array.now the requirement of my app is
User will be able to add or delete row.
second thing is there will be a hierarchy of table view, i.e ,on click of row the same table view should be reloaded with different contents related to that row.
what actually my requirement is user would be able to create folders,rename the folder ,move the content from one folder to another,delete the content of folder,delete the folder.
here the folder is row of a table.
anyone has any idea how to do this

try inserting the below code at the index of row in the did selected method. for eg:
if(indexpath.row==0){
[self.tableView reloadData ];
}

Related

How to delete tableviewcell automatically

I have an array like [1...100], and I display it in a UITableView. When I add a cell to that tableview, I want the cell before it to be deleted automatically. Is this possible? I tried many solutions, and I know how to delete a cell by using the commit editing style method, but the the cell needs be deleted automatically, not with user input.
You would have to change your model and then reload the table. Let's say, as per your example, that your table contains rows with 1 to 100 in them. Your model would look like this:
var model = [1..<100]
And in cellForRowAtIndexPath you would set the text of every cell to an item in the array. Therefore, if you update the model and reload the table view, that will "automatically" delete cells. Your adding function, which deletes the last cell before adding a new one, might look like this:
func addItem(n: Int) {
model.removeLast()
model.append(n)
tableView.reloadData()
}
This allows you to manipulate the model however you want, and then update your table without having to worry about working with removing and updating cells.

Editing a cell in Nat table

I have a Nat table with some data in it.I want to add a new row just after the selected cell.I was able to do it. Now I have to select the newly added cell(0,new rowPosition) and edit it too. Using the selectCellCommand I was able to select the cell but the problem is with editing the cell. when I try to get the cell from Nat table using the api getCellByPoition I get null. Now this happens when I have a scrollbar and few rows are hidden at the top.Selection layer works fine and selects the first cell of the newly added row but Nat table doesn't give me the cell for the same row position.How can I get the cell to edit it? I am firing the EditCellCommand for the specified rowposition and getting the cell editor from nat table using getActiveCellEditor method.
It seems you are not aware of the position-index transformations in NatTable. I suppose you try to access your object via index. But in scrolled state the position is not equal to the index.
Please read our getting started tutorial on this topic http://www.vogella.com/tutorials/NatTable/article.html#architecture_layers

Refreshing/releasing 2nd tableview from previous query in drill down tableview

I have a drill down tableview that is using sqlite.
The first one is a tableview where i load some categories using a SQL query.
When i click a row it's using the following query to show the appropriate records for the category:
#"SELECT * FROM table WHERE category IS ('%#')", sharedSingleton.category];
This works.
When i click the back button on tableview 2 and return to the category tableview and then touch another category tableview2 still shows the rows for the category i selected the first time.
I'm new to this stuff but i searched a long time and tried releasing objects or set value's to nil but is doesn't seem to help.
Am i in the right direction, how can i refresh or release tableview2?
Thanks in advance.
Yes you are in the right direction.
When selecting a row table 1 you might be calling a method which loads the second table view and assigning the data to be loaded to the corresponding table view,Which is fetched and filled when delegate/ data source methods of table view is called.
You might have created tableview as a different view controller class, which is initialized and data is reloaded for the first time. But even though you are fetching the second set of data its not getting reloaded automatically even after you are assigning it.
After assigning the data you have fetched into the obect which distributes it to tableview Reload the table data once you assign it to. you could call the one line of code to do this
[tableview reloadData];
Regards,
Jackson Sunny Rodrigues

UITableView data source update issue

I have UITableView which has edit button in all rows with tag as id of the data in corresponding row.In the first row i have button to insert new item when i click on button on first row to add new item,navigates to insert form,add data to database in that forms n bring back to original uitableview which i reload in viewDidAppear.New Item along with button can be seen in the table n also i can view (in my logs ofcourse ) my NSMutableArray get updated with new data n button with appropriate tag (i.e with new ID) ;which i have provided as data source to uitableview; while binding data.
Now But when i tried to edit my newly added item i got correct ID for my Data at the button tag which is clicked, but surprisingly ,now , same array which i have observed being updated while binding,has short of new data in array but surprisngly visible on uitableview
y is it so ????
Have you already tried [yourTable reloadData]; ?

custom tablecell valueForSelectedRow problem

I have created a custom uitablecell which contains several values. When the user selects a row, I want to be able to select that row's content for one of the values in the custom uitablecell. If the cell looks like this:
ba_type varchar2(20) P
source varchar2(20) P
row_qual varhcar2(20)
If the user has selected the 'source varchar2(20) P' row, I want to be able to grab the value of 'source' out for my next query.
thx,
wes
Strictly speaking, you've created a tableview cell that displays several values. Sitting in memory somewhere behind that is an array that contains the actual data. That's how MVC architecture works.
Ideally, you have some data structure in memory that corresponds to the cells. If you had an NSMutableArray in memory, you could retrieve the value by doing
// assumes one section in the table view
NSString* sourceForNextQuery = [dataSourceUsedToPopulate objectAtIndex: indexPath.row];
inside didSelectRowAtIndex
If you insist on retrieving the text from the label in the table view cell, when you create the label that contains it, add a tag (mySourceLabel.tag = 999). Then find that tag again by using searching for the tag, the get the text (UILabel.text)
But really, you want to separate the presentation of the data from the underlying model, and have the controller contain the data.