I have a table view controller where I show a shopping bag (or shopping cart). In each cell I show an image view, an a few labels with some information. One of those labels shows the quantity of products for that product. I want that when I press the edit button the quantity label becomes a stepper (or something like that) where I can change the quantity. I have seen that behavior on other apps (specific on Zara for iPhone, a clothes store) but I cannot figure out how to do that. All I have found on the internet is to segue to another view where you can edit an item, but that's not what I want to do.
How is it possible to implement such a behavior?
Thanks a lot!
You can try to add the stepper on the label, in the UITableView Method,
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
This method allows you to perform actions when a table view cell is selected.
Related
I'm the middle doing some project that involve CollectionView and property list. I want to do the image grid in the Collection View, and the image is the significance to proceed to the next page.
Here I want to do:
1) User click image in the collection view
2) Image will redirect to the next page and display the data that stored in the property list. The data is display according to the image that they click.
I'm using Xcode 6.
How can I perform such process?
Here is the almost similar example give by Apple. It will give you a good point of reference.
UICollectionView has a delegate which provides a method
- (void)collectionView:(UICollectionView *)collectionView
didSelectItemAtIndexPath:(NSIndexPath *)indexPath
When an item is tapped, the function above is called. Based on indexPath you can determine which item was selected.
In your storyboard, create a new UIViewController and create a segue from your UICollectionView to this UIViewController and make the segue as Push and name it 'collectionViewToUIViewController'.
In your didSelectItemAtIndexPath, call method
[self performSegueWithIdentifier:#"collectionViewToUIViewController"]
Also implement prepareForSegue where you tell the UIViewController what to display.
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.
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
I have an app that uses a custom UITableViewCell to display detail information after a user clicks on a given row in a table. I can't seem to figure out why the "Reply" button located in the cell is inactive and appears behind the table itself. I can't click on it, select it, or do anything. I used Interface Builder to add the button rather than programmatically add it.
I've tried changing a number of things including the cell's class and File's Owner, but can't seem to get the button to be active and working. I think the button is linked up properly with a connection to a method in the code.
Here's a minimal, complete example of the code:
https://www.dropbox.com/s/atcof58ciqbaojr/CustomCell.zip
Apparently I needed to tell the table view how high the cell was. This is what fixed it:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
return 157.0;
}
My iOS app is current transferring control to a detail view when an item in a UITableView is selected. This ia a quiz program, and I'd like to change the app so that it just redisplays the same table view with the correct answer highlighted when a row is selected. What's a good approach for doing this?
Is not clear to me if you know why the detail view is appearing. So I'll explain just in case. If you are giving control to a detail view is because somewhere in your code you are pushing that detail view. It depends on what kind of UITableViewCell you are using. If you are using one of the defaults styles, your detail view is probably been pushed in either:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
or
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
If you are using a custom cell, then you need to look for the method in charge of pushing
that detail view.
I think a good approach would be to:
Remove that pushing wherever it is.
Not to use an `UITableViewCellAccessoryType, if you are using one.
Do something similar to the following on your tableView:didSelectRowAtIndexPath:
Find the row for the right answer in your model array, according to tapped cell.
Use that row number to generate an NSIndexPath.
Use that NSIndexPath to find the correct cell with cellForRowAtIndexPath:
Call setSelected:animated: on that cell to highlight it.
NOTE: If your quiz has more answers than the amount of UITableViewCells that fit in the screen you should scroll your UITableView to the right answer for better UX.