iPhone dev: UITableView Cell's appreance modified when scrolling - iphone

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.

Related

Change UITableViewCellAccessory after InAppPurchase. Possible?

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.

Iphone UiNavigation controller types

In examples I have seen of UINavigationContoller and UITableView, switching to next view is usually triggered by tapping into that cell and pushing a different UIViewController on top of stack, but what I want is to switch to next view by pressing a next button in bottom of page, which I want it to load the same UITableViewController again but with different contents in each cell.
-Can I put that next button on bottom of page? and where
-Can I call the same controller (but showing different contents) and put on top of stack using the UINavigationController?
Because I want to be able to browse back previos pages.
You would generally do as you highlighted first and push a new UIViewController subclass onto the UINavigationController.
A UIViewController is supposed to manage one screens worth of content. If you plan on breaking that convention by presenting different information you are essentially going to have duplicated if statements to decide whether the user should be viewing the content from before or after the button was tapped.
UINavigationController's are good for hierarchal data where the content becomes more specific as you drill down. The UINavigationController will also manage the stack so that you can go to previous pages.
To achieve what you want to achieve (stated here) you should be using a UINavigationController with your custom subclass of UITableViewController when the user submits questions you receive your xml, parse it and then instantiate a new instance of your UITableViewController subclass and push it onto the stack.
You can add a button in the footer view of your table view. To achieve this have a look at tableView:viewForFooterInSection:. Then add an action to that button which allocs and inits the view controller with the new content and pushes it onto the stack.
Just make your UITableViewDatasource returning your number of rows plus one in the last section you have in –(NSUInteger)tableView:numberOfRowsInSection:. Set any content for that cell before returning it to the tableView.
Then only push a new UIVIewController, when the user touches that last cell.
You could also make the delegate of the UITableView returning nil on :
-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath for the cells you don't want the user select.

How to recreate the iPhone app store application detail view?

I'm trying to get a view that is similar to the the application detail view presented in the app store but I can't figure out how it is implemented. It looks like a UITableView with 3 or 4 custom cells. Does that sound right? Any insight would be great.
Thanks.
Nah it's not like that at all. What it is, is a couple of scrollviews (ie., the screenshots is just a scroll view tied to a paging control), directly above that is either a web view or a scroll view (hard to tell) -- with the actual content. Above the content you'll have a few items in the content view that holds everything, the app icon, name, company, etc. And at the very buttom, you can implement it as a table view if you want, but yes, you'll need custom cells, which isn't difficult to do, you just have to implement the tableView:heightForRowAtIndexPath: delegate, and return the appropriate height for each cell in that view, then in your tableView:cellForRowAtIndexPath: switch on the indexPath's row property, and if it's one type of cell, set it up how you need to, if it's another, do that custom cell, etc.
It's not really hard at all. I reproduce a view similar to this in one app that I work on in the store, and I do it pretty much just as I described above.

how to manage a stack of UITableViews without a navigation controller

I am new to iPhone development, and I am working on modifications to an existing iPhone app. The high-level overview of the issue is this.
I have a button displaying a pop-up containing a UITableView.
I'd like to click on a menu item and display a second UITableView with sub-items, including a back option. If the user clicks back, they go the original UITableView. If the sub-item has additional sub-items underneath it, it should (when clicked) launch another UITableView with these options. There is also a back button as a menu item that will allow the user to navigate to the previous menu displayed.
The challenge here is that I am not using a navigation controller. the original developer only wants to add UITable Views to the stack, add transitions between them as you go from one menu to the other. Most of the tutorials I have seen and tried utilize a navigation controller and Interface Builder to associate the UITableViews.
Right now, I have an XML data source populating the menu, and when I click on a menu item, the titles change correctly, but still uses the same UITableView to display the options - this has consequences of course, as some of the sub-items may not fit on a screen.
any thoughts on how this can be done? I can post some code if necessary, although I think the general description should be able to ring a bell with one of you smart guys!
This can be done in numerous ways.
I haven't done this first one, but you can probably create a UINavigationController and set its view to the appropriate frame (inside the bubble) hide the navigation bar and set the action of your back button to pop the current view controller.
Another method is to have multiple tableviews on one controller, the delegate and datasource methods have the UITableView as an argument so you can distinguish them when setting the height of your rows, headers etc and when returning a UITableViewCell.
The way I've chosen to deal with such configurations is to have one UITableView and have only the datasource change. When you reload, insert, delete rows or reload the whole table, you can change anything you want depending on the current datasource level. The easiest none animated way is to reload the whole table.
a) If your "options" go off-screen height wise (you want fixed height) table change the - (CGFloat)tableview:(UITableView *)table heightForRowAtSection:(NSInteger)section return value
b) If your "options" go off-screen length wise either make your cell's default textLabel flexible: cell.textLabel.adjustsFontSizeToFitWidth = YES; cell.textLabel.minimumFontSize = 14; or have custom cells (lookup subclassing UITableViewCell, which is recommended) for each datasource level.
If you subclass TableViewCells remember to have different dequeue cell identifiers for each level, so the table doesn't provide you with another level's cell class.
For the "stack" of tableviews or datasources, you can have an NSMutableArray with addObject for push and removeLastObject for pop.
For animations, UITableViews can animate their rows/sections for 3. (see documentation for insert, delete, reload - Rows/Sections UITableView class reference), for 2. you can even have UIView (if not CoreAnimation as Grimless suggested) animations, that move the current tableview to the left (setFrame:) and the next tableview from the right (setFrame offscreen before animation and then in place in the beginAnimation-commitAnimation clause), but make sure you add the tableviews in a container view (the bubble interior) that clips its subviews.
Oi. This is gonna be a tough one. My suggestion would be to maintain your own stack implementation. Then, use CoreAnimation to add/remove UITableViews from your main view controller to get animated effects. So whenever the user clicks on an element in the current table view, the appropriate controller creates a new controller and table view, and then your custom navigation controller pushes the old one onto the stack, removes the old table view from the main view, sets the new controller as the current one, and adds the new table view to the main view. Kinda messy, but I think it will work.

Having UITableView edit button outside of the navigation bar

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.