Creating a selection menu using Cocoa Touch and Objective-C

I am creating one application to view using Cocoa Touch. I need the menu to display with different themes for this single view, and I was wondering what is the best approach and how to do it.

Should I create a Master-Detail view? And if so, how do I get the detailed view as the initial screen loaded by the application. But I'm not sure if this is the best approach.

I also looked at things like pop over menu , but Id would rather find out how to achieve these kinds of things myself than just buy from offshore. Is there a class in Cocoa Touch that offers similar functionality? They obviously built this menu from scratch using Core Graphics, but is there an easier way to achieve this type of menu, perhaps with the UIButtons group, for example?

The code examples would be greatly appreciated, but I'm really looking for a better way to solve this problem, so I know which Frameworks should be familiar with.

TIA

+4
source share
4 answers

You can try using UICollectionView with UICollectionViewFlowLayout to create a grid of buttons that you can use to switch between different themes.

Without knowing more about what you want from your selection menu, how many topics you have, how you want to display it, etc. its hard to suggest one method over another. But since UICollectionViewFlowLayout is a predefined UICollectionViewLayout provided by Apple to display UIViews in a grid location, this may be a good way to solve this problem.

Here's how you could implement a UICollectionView with a UICollectioViewFlowLayout :

Header file

 @interface ViewController : UIViewController <UICollectionViewDataSource,UICollectionViewDelegateFlowLayout> { UICollectionView * themeSelection; } 

Implementation file

 - (void)viewDidLoad { UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc] init]; themeSelection =[[UICollectionView alloc] initWithFrame:self.view.frame collectionViewLayout:layout]; [themeSelection setDataSource:self]; [themeSelection setDelegate:self]; [themeSelection registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cellIdentifier"]; [self.view addSubview: themeSelection]; [super viewDidLoad]; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return 15; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath]; //Each cell is a theme that could be selected return cell; } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { return CGSizeMake(100, 100); } 
+2
source

How about using a UINavigationController and pushing a UITableViewController with a list of topics in the navigation stack?

You are not limited by the number of topics that you can offer, and this should be fairly easy to do.

Or you can use [UIViewController presentViewController: animated: completion:] with modalTransitionStyle set to UIModalTransitionStyleFlipHorizontal.

+1
source

If the number of topics is less than or equal to six, you can use the UIActionSheet with several buttons. In your view of the controller, click on the "Select Theme" button with the following code:

 UIActionSheet* as = [[UIActionSheet alloc] initWithTitle:@"Choose Theme" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Theme 1", @"Theme 2", @"Blue Theme", @"etc."]; [as showInView:[self view]]; 

At the top of your .h file, next to the class definition, add the following:

 <UIActionSheetDelegate> 

And the .m file declaration uses the following method:

 -(void)actionSheet:(UIActionSheet*)as clickedButtonAtIndex:(NSInteger)index { switch(index) { case 0: //It was theme 1 break; case 1: //It was Theme 2 break; case 3: //It was blue theme break; //And so on... } } 

Replace comments by switching to the selected topic.

Note: if you have more than six topics, you need something more like the solution discussed in this . Question about UIPickerViews in action sheets.

+1
source

There are many ways to do this. such as adding a UITableView to a UIActionSheet and displaying an actionSheet on a specific button. also UIPopOverViewController is best suited for this type of work.

The following is a useful source of code that may be useful in your case:

https://github.com/nacho4d/Accordion

https://github.com/kyoshikawa/ZPopoverController

0
source

Source: https://habr.com/ru/post/1492254/


All Articles