Adding a number picker to each table view cell - ios

I am very new to iOS development. Currently, I am trying to develop an iPad app for taking orders in a restaurant. The UI should be like this:http://www.dhtmlx.com/blog/wp-content/uploads/2011/02/ipad_menu_final.jpg As people suggested, it would be easier to start by creating a Master/Detail project as the basic structure. After going through a couple of tutorials, I know how to display detail contents when I select rows at master view. Now, my assumption is to add an UITableView to the detail view controller, and at each UITableView Cell, I want to add some text to describe the menu item and also an UIPickerView to let the user select the quantity of each item (like the pic in the above link). Am I on the right track? How can I add an UITextField and UIPickerView to each UITableView cell programmatically? Are there any examples or tutorials teach me how to do this?
Thanks in advance.

1 - THE VIEW : Create a UITableViewCell subclass (ex: MyMenuItemCell), with the properties you need
a UIImageView for the picture
a UILabel for the price (with some CALayer cornerRadius, backgroundColor, and borderColor tweaking)
another UILabel for the title describing the product
another UILabel for the description
a UIButton to get userAction, but handle that in another class, as this cell is the VIEW, and should hold no control logic, this is the CONTROLLER's part.
2 - THE CONTROLLER
You UIViewController should implement <UITableViewDatasource, UITableViewDelegate>. (or it can directly be a UITableViewController subclass, which provides some generic benefits, like moving the tableView when a keyboard is displayed. If you choose this 2nd option, and create the viewController programmatically, be sure to use the initWithStyle: method)
3 - BIND VIEW with CONTROLLER
However you choose to enable 'quantity pick' :
with some UIStepper (+ and - buttons) linked to a UILabel
or
in some dedicated UIPickerView displayed in a UIViewController embedded in a UIPopoverController
(or any other design you see fit)
you should write the code that triggers this action handling IN your controller, when UITableViewCell are instantiated / reused, in UITableViewDatasource method providing cells instances :
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

Related

Create properties for Static UITableViewCell Subclass

I decided today that using static tableViews would suit my app better than dynamic ones.
Each cell has a label, and a UITextField
I subclassed one of the static cells and then tried to create IBOutlets for the label and textField... only it wouldn't work. Zero IBOutlet functionality when it comes static cells apparently and their subclass
I can however drag in IBOutlets to the UITableViewController these cells are apart of
So, essentially I would have a UITableViewController with outlets for each cell, each cells textField, each cells label, and potentially any other properties I want to add to the cell
I didn't want that much annoying code so I tried using dynamics
I was able to create IBOutlets for each object the way you can normally expect
I again decided against dynamics UITableViewCells, and switched back to static...
ONLY the static cells now have IBOutlets connected to them (they didn't disappear or throw errors when i returned to static UITableView)
I can access the cells properties by using cell.textField which is a lot better than a billion IBOutlets for each object on the cell
My question is... Why can't I create IBOutlets on the subclass of Static TableViewCells
Is the way I did it the only way, or is there a better way? I would hate to keep switching back and forth, but it allows me to get rid of dozens of lines of code I'll do it
When you create IBOulet for a UITableViewCell and you try to connect them on your StoryBoard, go to the left bar (where the objects of your view controller are) and press Ctrl + Click over your custom cell. Then the IBOutlet object will appear in a popup and you will be able to link them.

UITableView, need to freeze first cell(s)

I'm using UITableViewController in order to use static cells.
Is there any way to freeze first cell so it's not scrollable? I'd like to other cells to scroll but first one to stay intact.
I was thinking about regular UIViewController with some stuff on top and UITableView under, but this won't work because I need UITableViewController in order for static cells to work.
The only other way to make it work is with UIViews and Scroll view, but then I don't get benefit of UITableView.
Is that possible?
EDIT:
Just to make it clear. I like to use UITableView with static cells because I have outlets and actions. Buttons, fields inside cells. I'd like to limit "coding" only to show/hide cells. I don't want to create UI inside code. I want to do as much as I can using Storyboard.
Not sure how to put views on section header using Storyboard. Is it possible at all? I only can set text caption.
Also! Even though I do have header (with test) it still scrolls with rest of cells. I need to make sure it stays on a screen.
You can use this delegate method and pass your custom view along with your sub control it will get stick at top :
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
return <your custom view>;
}

How to create a view for settings of my iPhone apps in Xcode storyboard

I am new in iOS programming and I would like to create I view for the settings of my app that looks like iPhone's one (like in the picture). Some of rows will call other views when taped and other will not.
What is the best way to do that? I thought about TableView with prototype cells, but is there a best way to do it? or a best-practice for what I want to do? Or maybe a tutorial online?
The fast way in Interface Builder:
Use a UITableViewController, make it STATIC and use the GROUPED style (all in IB).
You can setup the cells to show disclosure indicators (or not) in IB also.
You can segue directly from the rows or the UITableViewController to where you want to go.
If you segue from the UITableViewController, implement the "didSelectRowForIndexPath" method and call "performSegueWithIdentifier" accordingly.
A structure like this is best by UITableView.
First you select how many sections you want, and customize each section with a data structure that you have to be filled with (Probably an array.)
Then you fill up each rows inside
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
method, and call your value from the array/dictionary that you have.
for going to a next view when clicked upon
Use the method
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
Hope this helps
The best way to do that is using static UITableViewCell.
See UITableView Programming.
The optimal solution here is undoubtedly UITableView. This is because firstly, you have the need to display a list of options that would have external links to other pages and UITableView is designed and used for this purpose.
In an addition to that, if you want, you can also expand and collapse the rows of your parent TableView into a Child TableView i.e a UITableView as a subview of its parent UITableView.
Put up a UITableView and populate it with UITableViewCell. That will be just fine with the requirement you have.
Hope this helps.

Is it possible fix the position of first row on UITableController?

In my app I have used a UITableViewControllersub class to display a list of data. I finished every thing in the project, but the client needs the top row of the table to stay on top and not scroll with the rest of the content. I know this could easily be achieved using a UIViewController instead of a UITableViewController but would like to avoid this. I'm here for a final attempt to see if there is any way to fix some rows in a table view.
Please note that there are 4 different UITableViewController's in my project and they all have some complex logic in their table view delegate methods. This means a lot of work if I need to change all the UITableViewControllers into UIViewControllers.
Anyone have any ideas?
I have two suggestions for you:
More common practice is to use property of the UITableView
#property(nonatomic, retain) UIView *tableHeaderView
Second way to place your table view as child view and add another subview
UIView
HEADER UIView
UITableView
All you need to do is to implement method (declared in UITableViewDelegate):
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
return self.yourHeaderTopView;
}
You need to create the custom tableheaderview. For more refer this
Add 2 cells
use first as static and fill up the information as u want.
set the Reuse modifier of the second and call that second cell in the
cellAtRowForIndexPath method to use that second cell continuously

How to display label in UITableView

I created a UIViewController using story board in Xcode 4.2. Then added a UITableView object to it by dragging it on to the view controller. Then dragged a label to one of the cells of this UITableView and made label's text to be MyFirstLabel. Now when I run this in simulator I am not able to see the label. What am I missing ?
You must create properties for UILabel when adding to cell
let's say you have a UILabel declaration like this(and connected to the object you drag on storyboard)
#property(retain, nonatomic) IBOutlet UILabel* yourLabel;
in your .h file and
#synthesize yourLabel;
in your .m file. After initializing the cell(on the cellForRowAtIndexPath delegate method)
add your label to the cell like this [cell.contenView addSubview:yourLabel]; I hope this helps-if not, please give some more details about your problem
You should see the label. Make sure you have static cells for your table view. You do this by selecting the table view and change this in the inspector. Now you can create the exact number of sections and rows, including the content, right in storyboard.
If, however, you want to change the content of the label, you have to create an IBOutlet, still using static cells.
If you want to vary the number of sections and rows you will have to go with dynamic cells. In this case you should see the label if you have the correct Cell Identifier set in storyboard and referenced in your table view datasource method cellForRowAtIndexPath.
EDIT:
As has been pointed out, you cannot use static table views if not embedded in a table view controller (which claims the whole screen). So here is the workaround:
Option 1: you make it into dynamic cells as mentioned above and implement the datasource protocols in your ordinary view controller. You could then insert the label in code.
Option 2: as option 1, but with subclassing UITableViewCell where you can design the cell with a xib and create the necessary outlets.

Resources