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];
}
}