Ordering System ideas and meal system ideas

Source: Internet
Author: User

Ordering System ideas and meal system ideas
Ordering System ideas

Step 1: Observe and implement the UIPickerView data source.

Step 2: load the plist file and store the data in the NSArray array.
-(NSArray *) foodArray
{
If (_ foodArray = nil ){
_ FoodArray = [NSArray arrayWithContentsOfFile: [[NSBundle mainBundle] pathForResource: @ "foods. plist" ofType: nil];
For (inti = 0; I <self. foodArray. count; I ++ ){
[SelfpickerView: nildidSelectRow: 0 inComponent: I];
}
}
Return _ foodArray;
}

Step 3: Observe and implement the UIPickerView proxy method and listen to the method selected for each row.
# Pragma mark-proxy method implementation

/** Total number of groups */
-(NSInteger) numberOfComponentsInPickerView :( UIPickerView *) pickerView
{
Return self. foodArray. count;
}

/** Number of rows in a group */
-(NSInteger) pickerView :( UIPickerView *) pickerView numberOfRowsInComponent :( NSInteger) component
{
NSArray * foods = self. foodArray [component];
Return foods. count;
}

/** What is displayed in a row */
-(NSString *) pickerView :( UIPickerView *) pickerView titleForRow :( NSInteger) row forComponent :( NSInteger) component
{
Return self. foodArray [component] [row];
}

/** Select */
-(Void) pickerView :( UIPickerView *) pickerView didSelectRow :( NSInteger) row inComponent :( NSInteger) component
{
If (component = 0 ){
Self. fruitLabel. text = self. foodArray [component] [row];
} Elseif (component = 1 ){
Self. mainFoodLabel. text = self. foodArray [component] [row];
} Elseif (component = 2 ){
Self. drinkLabel. text = self. foodArray [component] [row];
}
}

Step 4: Listen to random UIBarButtonItem events
-(IBAction) randomClickBtn
{
For (inti = 0; I <self. foodArray. count; I ++ ){
// Calculate the number of rows according to the group
Int cou = [self. foodArray [I] count];
// Obtain the selected
Int oldRow = [self. picker selectedRowInComponent: I];
Int row = oldRow;
// If the last one is equal to the next one, it is random.
While (row = oldRow ){
Row = arc4random_uniform (cou );
}

[Self. picker selectRow: row inComponent: I animated: YES];
[SelfpickerView: nildidSelectRow: row inComponent: I];
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.