updating tableViewCell with modifications done in another view - iphone

In my app am using tableview in which each cell am adding UIScrollView, in that scrollView again am adding UIView(this view is adding from another view class). When touch actions of view is performing but when i scroll the table all the modifications in view is reloading with what is there at the time of loading.
So how can we save the modifications of view which are done in another class in present tablecell.
in touchesEnded method am using
[music.createTableView beginUpdates];
[music.createTableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationNone];
[music.createTableView endUpdates];
Any help or suggestion.
Thanks in advance.

Suppose, you are using NSArray to show data in rows of tableview. Inside that, you will keep another NSArray to show array of UIViews inside a every row. If you use NSDictionary to store data of UIView, you can set a flag in that dictionary which will change according to user touch. Hope it will help you.

Related

Update UITableView While Looking at View?

I am currently building a UITableView that reads an array and displays it on a TableView. I am continually adding to the array I would like to have a button on the view that once is clicked it updates the UITableView.
How do I implement a reload of the UITableView from the new array I just built?
If you are adding and removing items one to a few at a time you will likely want to implement the animated table view methods for insertion and deletion.
When you add or remove an item from the table view you will prepare by calling [tableView beginUpdates] make your array modifications and then call [tableView endUpdates]
Between the begin and end update calls you will perform the actually deletion/insertion.
For deletion you should use
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationBottom];
Notice UITableViewRowAnimationBottom you will want to play around with this to get the best animation depending on the position of the element. Also iOS5 has a enum value something like UITableViewRowAnimationAutomatic and it will use the best option.
For insertion you should use
insertRowsAtIndexPaths:withRowAnimation: the same way I show above with delete.
For more info check out the section with these methods listed in the UITableView class reference
The function you're looking for is [self.tableView reloadData];. Here's a link to the Apple documentation for UITableView.

Update UITableViewCell without reload

So here's my situation:
I have a UITableView where each cell has some buttons.
In the cellForRowAtIndexPath I set the indexpath of the row so when the a button is clicked I know what row was clicked.
One of the buttons is a delete button and when pressed I remove the backing data and delete the row from the table.
The problem I'm having is that after I delete a row the indexPath's of the other rows are incorrect as the other rows have not been redrawn. The only way I can find to redraw the table is to call reload but this messes up the animation.
I figure this kind of problem must have been addressed before. Does anyone have any suggestions on how to get around this? I'm ok with changing the way I've designed my buttons to work if there is a better way.
Think you need to use this...
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
Apple reference!
You should be able to redraw the tableview without a full reload by starting and ending an update like this:
[tableView beginUpdates];
[tableView endUpdates];
call the method:
- (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
It is better not to store the indexPath with the buttons. In the button action handler (which is either a method in your cell subclass or in your viewController) you could identify the cell, and subsequently determine the indexPath using -indexPathForCell:.

Why my tableView doesn't update without scrolling it down?

I am making an nav based app. in my table view i am parsing a xml and showing its data. when i enter new feed item in my xml and click refresh button, my data updates but it didn't appear in tableView untill i scroll it down. When i scroll it down it appears. Can anybody tell me why its happening like that? I want new data appear when i enter the feed item without scrolling my tableView down. Thanx for help
you need to call [self.tableView reloadData] to update the tableView with new contents
Did you call [tableView reloadData] when the data has been refreshed?
You need to reload the cells (or the entire table) for the new data to appear.
Depending on if you return parsed results right away or all results after the entire xml-file has been parsed.
The code to update the table is:
[myTableView reloadData];
You have to call [tableView reloadData] to refresh the data from the UITableView.
Call [tableView reloadData] when the parsing is completed
I'm not exactly sure what you mean. A simple reload is:
[myTableView reloadData]
in the UITableViwController
[self.tableView reloadData]
If you scroll down, new cells that are rendered will use the new data. but cells that are on display have to be told to update immediatly.
Not just -reloadData, you can use any of these:
reloadData
reloadRowsAtIndexPaths:withRowAnimation:
reloadSections:withRowAnimation:
reloadSectionIndexTitles
Basically, you'll need to tell your tableview that your data has changed so it knows to change that. You can do it with fancy animations and whatnot so that the user isn't confused when what's displayed on screen suddenly changes.

IPhone custom UITableViewCell Reloading

currently I'm struggling with this problem:
I got a UITableViewController that displays a tableView with different custom cells.
One custom cell displays a number (by a label). If you click on this cell, the navigationController moves to a UIPicker where the user can select the number to be displayes.
If the user moves back, the cell should display the updated value.
Problem:
I managed to reload the cells by calling
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.tableView reloadData];
}
in the UITableViewController.
This works only, if I don't use dequeueReusableCellWithIdentifier for the cell (tables won't show updates otherwise).
But in this case, memory usage grows and grows...
In addition, the program crashes after about 15 movements to pickerView and back - I think because the cell that should be reloaded is already released.
How can I update a reusable custom cell every time the view appears ?
What is the best solution ?
I think retaining cells should not be used ?
A general approach is to avoid reloading the whole table if only one cell is changed.
In such case, just get the reference to the UITableViewCell you want to "refresh" and invoke a [self setNeedsDisplay] from the main thread on it to trigger its refresh (will call the drawRect on it to trigger its drawing).
Have you set the appropriate id in the NIB? It has to be the same as you use when calling dequeueReusableCellWithIdentifier:
See step 3 here

Change the table View when segmented Control is tapped. Exactly as in APPSTORE app. How to do it?

I am having a SampleViewController in which a segmentedControl is added at the top below nav bar(not inside it).Now below the segmentedControl i want a tableView which loads from another class CommonTableViewController. When a segment is tapped the a new tableView from same CommonTableViewController should be loaded. How can it be done?
thanks in advance.
I use an array to populate my tableView...
In my segmentedControlClicked method... I change the data in the array based on which segment was selected and then use this line of code:
[self.tableView reloadData];
If you already have 2 UITableViews then just remove the first from the screen and add the other. LIke
[tableView1 removeFromSuperview];
[self.view indertSubview:tableView2 atIndex:self.view.subviews.count];
Depending on the case, you might also want to consider haveing one tableView and just changing the data.