Having UITableView edit button outside of the navigation bar - iphone

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.

Related

How to add an "Add Button"- Button

I'm looking to make a button which creates new buttons.
So there are already 3 buttons created by me with ViewController.
And on the bottom should be a "create new button" button. So the user can create as many buttons as he wishes. And every new button should be stacked under each other.
https://imgur.com/ttDZQU1
Here is how I build it on ViewController.
You have some ways to achieving this result. You can create a stack view and push the buttons to it. You can programatically add buttons to the screen by creating new UIButtons every time the users click the add button, or you can create a table view, and add a new cell every time the user clicks it. This last approach already supports scrolling (For when your user clicks tens of times, you'll need to able to scroll the screen so they can see the buttons outside the visible frame). In case you choose to go with the first or second, don't forget to add an UIScrollView to your View.
The steps to get this result with a tableview (3rd approach are):
Create a UITableView in the view controller's storyboard.
Set the UITableView datasource and delegate to the view controller
Create a UITableViewCell inside the UITableView, and set its identifier to something related to cell, like "buttonCell", for example.
Add a UIButton to this newly created UITableViewCell, and pin the constraints accordingly.
in the View Controller .swift file, create an outlet for the UITableView
in the tableView delegate cellForRowAt, don't forget to use the right identifier (in our example, "buttonCell").
if you get lost somewhere in the steps listed above, check some tutorials to create a tableview, such as: https://www.ralfebert.de/ios-examples/uikit/uitableviewcontroller/

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.

Switchable subview in window for iphone app

I've been looking everywhere but can't seem to find any examples/tutorials for my situation (not sure how to google it..)
So i have a window where a portion of it should be static (buttons and such) and there is a dynamic part (bottom leftish) that should change subviews.
So what i'm looking for is a way so that clicking the buttons in the static area will change the dynamic area to a view of my choice. I have no idea how to do this using the IB, but doing it programatically seems the only way. Any suggestions(I do not want to use a tab bar controller)?
Oh, and is there a benefit to making views and such programatically vs through the IB?
Thanks!
You can also achieve it programatically. Just create another viewcontroller class (as many as u want). In the loadView method of it create a UIView in the coordinates where u want to add the subview in the current view. Now create an instance of this viewcontroller class in the currentview controller and add it as a subview. You will get the subview at the desired location.If u want to change it dynamically create as many views and then add them to the array and change them whenever the button is clicked.
Hope this helps.
You should perform the switch in your view controller. The static buttons can have their actions hooked up to that controller (in IB), which can have an outlet (in IB) to the subviews and perform the swap.
As for when you should use IB, see this question.
You can do it from interface builder as well. You just need to take viewController from interface builder drag-n-drop to main window. assign IBAction to all buttons to add different viewController's view to main window just make their frame some smaller.
if u want to change or views by click on button then u chose segmentcontrol switch. and cod for each segment like as when click on segment 0 then open first sub view and when click on segment1 then open second sub view. And make by default unselected so that ur static view will appear initially lunching of view.

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 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.