I've a TabBar Application with 5 tabs. In the fifth tab, I manage the InAppPurchase without problems. When the user buy a content and switch to first Tab (it has a TableView), I would like to change the UITableViewCellAccessory from none to UITableViewCellAccessoryDisclosureIndicator.
It's possibile?
I don't understand where I should insert the change of UITableViewCellAccessory.
Thanks,
Alessandro from Italy.
Hello Alessandro from Italy,
Well the thing you would have to do is to implement the cellForRow:atIndexPath: method from the UITableView class, in that method you would probably have a conditional of this type:
if (IN_APP_PURCHASE_DONE == YES){
[cell setAccesoryType:UITableViewCellAccessoryDisclosureIndicator];
}
Edit:
To be sure you are updating the UITableVIewafter you purchase the extras, you should check in the tabBarController:didSelectViewController: method of the UITabBarControllerDelegate object when your table view's view controller is going to appear to reload the data.
El Developer's solution doesn't quite work, because cellForRow:atIndexPath: is only executed when the cell is first being created. So if the tab with the tableViewCell is opened before making the in-app purchase, the cell will have been created already, without a disclosure indicator.
Here's what you need to do:
In the viewController for the first tab, make a UITableViewCell instance variable.
In cellForRow:atIndexPath: when you create the cell that needs to get the disclosure indicator, set the instance variable to that cell as well.
Also in the first viewController, make a method that will add the disclosure indicator to the cell.
Call the method above to set the cell's disclosure indicator when the in-app purchase happens. For example, you could make the first tab's view controller the delegate for the fifth tab's view controller.
Related
I have a table view with one custom cell that I have already built and hooked up. When the user taps the add cell button I want it to add a different custom cell. I don't know where to start this process. Do I build it on the storyboard then hide it? Or what is the best means?
You should create all of your custom cells in the storyboard, and then implement UITableViewDataSource methods, where you return whatever cells you want.
Check out the documentation
I have a UITableView of customers where a row/customer is selected. The user can then push another view on the UINavigationController stack to add a new customer. When I pop the child screen and return to the UITableView the previously selected row is no longer selected.
I can re-select the row in viewDidAppear() but it looks bad as you can see the deselect and the select. Is there a way to maintain the selected row when returning from the child screen?
I assume you are using a table view controller, as otherwise it is your responsibility to write this behaviour anyway. In a table view controller, though, it's easy. Just add in viewDidLoad:
self.clearsSelectionOnViewWillAppear = NO;
That will keep the row selected, unless you manually deselect the row or the user selects another row on the table.
If you select it in viewWillAppear:, it should get selected without the user seeing it. Would that solve your problem?
You need to call:
[tableView deselectRowAtIndexPath:indexPath animated:YES];
This is found in the didSelectRowAtIndexPath delegate method for a UITableView.
By default, a selected row gets deselected (with animation) when you return to that VC.
So, if you push a DetailViewController, the cell stays selected until you return to the RootViewController and then gets deselected automatically.
I used to have such a problem too. Make sure to always call the superclass's implementation of methods such as viewWillAppear, viewWillDisappear etc.
Also, do not call deselectRowAtIndexPath: manually.
This is possible :
Only in once case: If you have the static content in TAbleView,
just reload the TableView in ViewDidLoad only, not in View will Appear.
whereas make sure, you don't allow table to reload anywhere in same class in any method. Then you can achieve what you want.
The cell get deselect because of reload the TAbleView.
But for Dynamic content, you need to use the delegate method:
- (void)selectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition;
In this you need to pass the indexPath which you want to show selected with the scrollPostion same as tableviewposition.
You cannot have a tableViewCell selected all the time. It gets back to normal once it serves its purpose. I think you meant highlighted or appear to be selected, and I am answering the question based on that.
Get the row that was selected at the cellForRowAtIndexPath. When you pop your navigation controller and come back to the tableView, go the the cellForRowAtIndexPath and have that cell highlighted (You can use any UIColor as you wish) - there is no specific way to highlight stuff - use your imagination - Default highlight style is Blue, while the text is White.
How is this done ?
Find selected row in cellForRowAtIndexPath
Store is in an external variable / or NSUserDefaults and you can also use NSUserDefaultsto communicate between screen to find out if item was popped from that screen.
[tableView reloadData] in viewWillAppear
Check for NSUserDefaults value in cellForRowAtIndexPath and modify that cell with cell.backgroundColor or something.
Without some code, I can just give an advice : stop using [tableView reloadData], use [tableView beginUpdates], [tableView endUpdates] and – insertRowsAtIndexPaths:withRowAnimation: and – reloadRowsAtIndexPaths:withRowAnimation:. Things should work as expected.
I have a two tabbed application. The first tab is a NavigationController that has a few TableViewControllers in it. The second tab is also a NavigationController that has a TableViewController in it.
What I'm trying to achieve is: When someone clicks on a button in the TableView inside first tab, I want to add the the clicked row to the TableView inside the second bar.
I'm already saving the information when it is clicked to NSUserDefaults. When I quit the app and restart, the second bar shows the updated info. But it doesn't show the updated rows if I switch to it while the application is running.
How can I make the second bar reload/update dynamically with the updated rows when someone does sth in the first bar?
I've called [self.navigationController parentViewController] successfully to get the tabBarViewController, which is the highest level, when the the tableview in the first bar changes. How can I get to the TableView inside the NavigatinController inside the second tab from there to have it update itself? Or should I be doing this another way?
Thanks.
i think you can call reloadData in second bar's view controller function
-(void) viewWillAppear:(BOOL)animated
{
[tableView reloadData];
}
You could call the reloadData method on the UITableView within that TableViewController. Honestly, I think you should be using CoreData but I don't know enough of the structure of your data so... try that?
I'm working on an iPhone application.
This is a tab bar application, containing a navigation view controller within one particular tab.
I have a table view in the navigation view controller.
In this groupe table, I need to add some UISwitch to some particular items.
for instance, I have the following sections:
accounts
twitter (&)
facebook (&)
linkedIn
publication
twitter (*)
facebook (*)
linkedIn (*)
connection
stay connected (*)
about
about
I need to have the UISwitch for the ones with the * but not for the other ones.
I manage to add the UISwitch for thoses ones using condition on indexPath in the tableView:cellForRowAtIndexPath methods.
BUT... when I scroll the view... the UISwitch are added to some other items (the one with the & above).
Could you please help ?
Thanks a lot,
Luc
It almost certainly is a problem with your code for cell reuse.
When you dequeue a cell to reuse it, it is not reset to a fresh state, instead it still has a UISwitch if a UISwitch was added to it before.
So whenever you dequeue a cell for reuse, you will need to assume that it might have a UISwitch subview, and remove that subview if you don't want it before you return the cell.
I have a UIViewController, and within that view i have UITableView added in IB
The UITableView displays the items from my array beautifully
I would like to be able to edit the items i.e delete them
BUT The UITableView does not have a navigation bar, and i am not using a navigation controller within this app i am just adding and removing views manually.
What i would like to do is place an "edit" button somewhere else within the view ... is this possible? and how might i go about this?
Put a button somewhere. In an action connected to it set TableView's editing property to YES - it should work fine. You also need to implement delegate's editingStyleForRowAtIndexPath method (return UITableViewCellEditingStyleDelete to allow to delete cells).
You could make one special cell (e.g. 1st row, 1st group) a button by implementing a adaequate didSelectRowAtIndexPath.
Or you could put buttons for editing/deleting in each cell (if single deletion/editing makes sense).
Or you could place the UIIableView on a super view wich also contains the button(s) as sub views.