How to duplicate view but in a different page? - objective-c

I have a view in my app that dynamically creates certain data. I want to be able to create a new view just like the old one, but on a different "page" of the app. Is this possible, and how would I go about doing this? A good example would be the Home Screen on an iPhone. When the number of apps reaches a certain amount on one page, it moves on to the next page and continues putting apps (or in my case data). I have a button that writes objects onto the screen, and stores them in an array. I want it so that when [myArray count] > x, the next object placed will go to another page, but identical to the first one.
Any help would be appreciated!
~Carpetfizz
Things I've tried (that didn't work):
Create an NSObject class that instantiates the view through [myView viewDidLoad], and is activated in myView.
Create a separate view controller that does the same thing as above

You should try using a horizontal UIScrollView (with pagingEnabled set to yes) and a UIPageControl. Check out this tutorial. Another option that creates similar functionality in a little more modern fashion is the UIPageViewController.
Update: I recommend trying out SGPagerView. I just tried it out in the simulator and it looked like a fairly simple implementation.

Related

Cocoa app design recommendation

I have a Mac app that needs to be based on multiple modules. That is, a single window with multiple views, and the default view with a menu. That menu should open one module on the default window and then if I select another module, the contents of the window should change with another view. Those views also have different states, so I made multiple views for each module.
In a nutshell, my app is a single AppDelegate.h/.m, a single xib file, with one NSWindow object and multiple NSView views. Those views have different states, so I load different other related NSViews.
To load a view, I use [window setContentView:viewNameView]; which I know that causes the old NSView to lose state, so I need to keep them all in memory for each module.
Is this the right approach?
Thank you!
You don't describe how and where you want the menu but a widely used method is to have a sourcelist on the left and the content on the right. You see this everywhere including Apples own apps.
If you create a sourcelist on the left of your window and place an NSBox on the right side.
Set up the sourcelist (NSOutlineView) to react to - outlineViewSelectionDidChange: which is an NSOutlineView delegate method.
Here you can check the identifier on the selected item in the menu and set the content view for the NSBox accordingly with - setContentView:
Here's a great introduction to using NSOutlineViews for anyone interested.
Edit: Depending on how many views you have it might be easier to have an NSTabView (in tabless mode) and just switch tabs in the - outlineViewSelectionDidChange: method. This is also widely used and the user won't see the difference.
You will want to look up NSWindowController for managing your window and xib, and NSViewController for managing views. The app delegate shouldn't do much (in fact you probably could remove the header file and merge it with .m).
Some references to look at:
https://www.mikeash.com/pyblog/friday-qa-2013-04-05-windows-and-window-controllers.html
https://developer.apple.com/library/mac/samplecode/ViewController/Introduction/Intro.html
Yes that will work. What you may end up needing as well, is a custom Navigation Controller. Unfortunately Cocoa doesn't have an NSNavigationController, so you'll have to write something on your own. But basically yeah what you'll do is swap out the contentView with the next view you want to display-- and keep a stack of views you've navigated to so you can support going back (or you could use a dictionary to add transition keys to create strongly linked transitions)
Here's an good example somebody posted in a previous thread-- if you just search for Cocoa Mac Navigation Controller you should find some helpful results :)
Mac OS X Cocoa multiview application navigation
Another thing that you may want to keep in mind, which came up for me, is if your views are of different sizes. If they are, and you are using auto-layout, you will need to update the constraints to resize the window appropriately as views are swapped out

Questions about creating 'Camera Roll'-esque functionality

I am fairly new to Objective-C so forgive my ignorance ahead of time =] Here is what I have so far:
The application is a tab bar style application
The view, as relevant to this post, contains several buttons that when clicked pull down different types of images
On click of the button an Array is populated with the data returned from the web service
A new view is displayed with a UIImageView inside of it
Now here is what I am hoping to get clarification on (or simply ideas)
As I said the application itself is a tab bar style app but I am having some trouble with the third view I've added. Currently when I click on a button the view loads correctly but it is loading inside of the Tab Bar view area. This isn't optimal and I would like for this new view to be displayed overtop of the Tab Bar thus taking up the entire area on the phone. I am opening this view from inside the View Controller that contains the button (which is a tab view) like this:
UIViewController * browsePictures = [[UIViewController alloc]initWithNibName:#"PictureGalleryViewController" bundle:[NSBundle mainBundle]];
[self.view addSubview:browsePictures.view];
On this third view I have a UIImageView (I am not sure this is the correct view for the app) that needs to be populated via the data that is returned from the web service. Returning binary data, as I found out, is very inefficient via JSON so I am returning URL's which means I will need to make a call out to the web for every image returned. I am ok with this I am just curious if there is a better way to do it.
The functionality I am trying to achieve with this third view is similar to the Camera Roll functionality of the iPhone. In this case when the user gestures to the left or the right it would move the current index of the array up or down one and load the next photo in the array. I am not sure how to implement this functionality.
I think that is all for now. Thanks!

XCode/Cocoa Mac Changing Views

I'm having trouble figuring out how to change between different custom views in my XCode project.
I have my Main nib file, consisting of 1 main window, and 5 custom views. The main window consists of 5 buttons, all which need to connect to the different views. So for example I click on button 1 and it closes the current menu and loads custom view 1.
I'm having trouble figuring out how this would be done.
I guess I would create IBOutlets for the 5 different buttons and the 5 custom views, and connect them to different methods such as openView1, openView2, where each method would close the current menu and load the custom view?
Could anyone help me code-wise how I would achieve this?
Any help greatly appreciated.
Thanks
So essentially you want a tab view?
You can make an NSTabView in Interface Builder. Set the number of tabs to 5. Then lay out the contents of the views you want inside that.
If you are happy using the standard system provided visual look for your tabs, then you're done. If however you want to have custom buttons that switch tabs, read on.
With your tab view selected, set its style to Tabless:
This makes the tab buttons disappear. That means that switching between views needs to be done through code. First you'll need an IBOutlet that represents your tab view itself: connect that up. Then write an IBAction method for openView1:, that might look something like this:
- (IBAction)openView1:(id)sender
{
[tabView selectTabViewItemAtIndex:0];
}
Make yourself a button (that sits in your window somewhere outside the tab view, otherwise you'd only be able to access it from one tab!) and connect it to this action.
This is probably the easiest way to get going with an interface like this. There's a whole bunch of ways to improve on it depending on how you want to structure your code. For instance, it sounds like you're coming from iOS development, where you'd make a UIViewController for each tab. Well, on the Mac there exists NSViewController, so you can use a similar pattern: but if you do you'll need to write some code that handles getting your view controllers' views into your tab view. It doesn't happen automatically through Interface Builder like it does on iOS. This tutorial should get you started if you choose to go that route.

Manipulate UI from AppDelegate

I am a newbie in all this as will be apparent really soon.
I am using the iOS: Application: Tabbed application template. I have placed a UIImageView in the first view and two standard rounded buttons. One button is attached to an action in the FirstView Controller which places a picture into the UIImageView. The second button is attached to an action in the AppDelegate which calls a method in the FirstViewController which in turn places a second picture into the UIImageView.
The AppDelegate method does not replace the picture. It doesn't crash… it just does not seem to do anything.
How can I manipulate the view in the First and Second View Controller from the AppDelegate?
#dasdom
Well that's one issue explained. I've been reading the theory of MVC and trying to put it into practice now. Short version is I am trying to write a Battleship app for practice. Was planning on using the first screen to setup the game pieces, prefs, etc.. and use the second screen for actual game play.
I've created another class to use as my "brain center" but I ran into the same issue of not being able to manipulate anything on the screen for the first or second views. (That's why I tried the appDelegate).
That's my life story right now… can you throw some pointers my way on how to proceed and how to solve my one of many problems?
First you shouldn't do that. The AppDelegate should only be responsible for bringing the first view onto the screen.
Second you should have a look into the Model-View-Controller design pattern. Search for it in your preferred search machine.
But I you really still want to do that you should have a look into delegation and/or notifications. For example you could send the First View Controller a notification from the AppDelegate to change the image.

UITableViewController Dynamic Drill-Downs

In a table-view that contains say 10 cells, is it the case that we need to create 10 separate UITableViewControllers to handle the different views loaded by clicking on each of those 10 cells?
That doesn't seem very efficient - especially in situations where large amounts of data (and thus tables/menu) need to be displayed.
How can you write a dynamic UITableViewController, that can accept any data-set (like an Array) on the fly and display its contents - and do it in a recyclable manner, so that it can be recreated again and again for each cell that is clicked?
I have it mostly working in an app I'm building - the only thing I don't fully understand about the method is how the incrementing of the "CurrentLevel" works since it seems like the variable would just keep getting reset since the controller calls itself.
Anyhow, the concept is that every time someone clicks a cell, a new instance of the UITableView controller is called and a new level is generated and added to "the stack", and a navigation controller is able to track what is in the stack and allow you to browse back to the previously loaded views.