Questions about creating 'Camera Roll'-esque functionality - objective-c

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!

Related

How to duplicate view but in a different page?

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.

Splitview Control navigating views

I am working with the SplitViewController for the iPad for the first time and trying to convert me iPhone app to run on the iPad. I have a couple of cells in a section such as Name, Phone Number etc in a navigation controller that i would like to adapt to work with the split view. I essentially would like the User to view the fields they can enter on the masterview of the splitview and when they tap a cell, the corresponding view should appear in the details view on the right. Can anyone point me in the right direction to get this functionality?
If you are okay at doing some self-learning, I would suggest simply creating a Master-Detail application in XCode. IMO that has a pretty nice template of how to set up the master and view controllers in a split view, and it will properly set up your details controller to handle hiding the master when going portrait.
In your code where (I'm guessing) you push a new view on in the iPhone version, you should just check the device type (or if self.splitViewController is set), and instead of pushing a new view on, modify the detail. The detail view controller will always be set to [self.splitViewController.viewControllers objectAtIndex: 1]
If you want more fine-grain control over your split view controller (showing the Master View as part of the SplitView when in portrait, or hiding the Master in landscape as well), I'd recommend using the excellent MGSplitViewController on github

Increasing number of living Views

I've set up a really simple project using storyboards including two views as shown here: http://i.stack.imgur.com/iRx21.png. The navigation can be done by either selecting a cell in the custom table view or hitting the back button labelled with "<<". Everything works fine except the following:
when I switch between the views, every time an instantiation happens. The profiling shows an increasing number of view objects. I would like to keep only one of each view and instantiation should be happen only once. What am I doing wrong? (I'm using ARC.)
Thanks in advance!
You should not link your back button to the parent view controller. This is what causes the new instantiation.
The way to go is to embed the table view into UINavigationController (in IB, choose Editor -> Imbed In -> Navigation Controller. Then change your segue to a Push segue. You can of course hide the navigation bar etc. to make things look exactly as you like. Then, link the back button to the controller with an IBAction and in the handler do a simple
[self.navigationController popViewControllerAnimated:YES];
This would be the appropriate logic of what you are doing. Of course, you can also push the web view modally and then handle the button click with
[self dismissModalViewControllerAnimated:YES];

Two view controllers (with nibs) acting on the screen at the same time

Just as a disclaimer, I am an iOS beginner, in a pretty unique position. I'm an intern learning on the job, with a hard deadline for a test app, with specific specs. So I unfortunately don't have the luxury of learning all that I should about xCode and objective C.
Anyways, I am trying to create a navigation menu similar to the iPad's slide out menu. I've looked at plenty of sample code given in response to questions like this in the past. It all works perfectly fine, but I can't understand all of what they're doing. I think this results from being fairly bewildered by view controllers and delegates. And, since I'm supposed to be writing this all by myself, I can't just build off of their existing code.
My plan for this working is to have one main view controller, containing the navigation menu in a table view. This is hidden behind a normal UIView, until a button is pressed, at which point the normal UIView slides offscreen enough to reveal the menu. Upon selection of a menu item, the normal UIView would slide back to its original position, and be replaced by the relevant UIView, controlled by its view controller. In other words, clicking on the menu item relating to "Home" would load the homeViewController.xib, controlled by the homeViewController. This would be loaded in that normal UIView subview, on top of the tableView.
I'm able to load a view in that normal UIView as a result of a button press.
homeViewController *_homeViewController = [[homeViewController alloc]initWithNibName:#"homeViewController"];
[self frontView] = _homeViewController.view;
There may be some syntax errors in that code, since its from memory. I'm not able to access the computer with my code on it at the moment, but that's the general gist. Basically, that places the home view nib on the frontView (that normal UIView that's over the table view), but its not connected to homeViewController. Or at least I think that's the issue, when I press a button, that's correctly connected between the nib and the homeViewController.h, and only set to NSLog in the .m file, the application crashes.
Any idea how to connect this nib to its viewController when displayed in this way? Or, to create the nib in IB, without the associated .h and .m files, and use the main view controller as the homeViewController as well? Or, if my logic is inherently flawed, what SHOULD I do? Something with NavigationControllers?
EDIT:
I also tried a new approach- changing homeViewController's file owner to viewController, and connecting the button on homeViewController's action to viewController. This too caused a crash upon pressing the button. I really think the issue is with having multiple view controllers acting on screen at once, or having multiple views from separate nibs, controlled by one view controller on screen at once.
I suspect that your immediate problem is that _homeViewController is being freed as soon as you leave whatever method that code is in. To fix this, create a strong property in this class that holds the _homeViewController for as long as its view is needed and allocate it to that property rather than a local variable. That way, buttons (or whatever) that are part of that view still have a valid controller object backing them.
In the long run, pushing or presenting view controllers when you need the screen to change is a much better strategy but, as I said, the immediate problem.... :)

Button push to specific tab bar item?

I thought this is quite simple but I can't seem to find the answer. I have a view controller with 3 buttons, one of these buttons has a push segue to a tab bar controller. When pressed I presume it loads the '0th' tab item which is the fine for the first button but how do I then get the other two buttons to push segue to the other two tabs?
I have read a lot of articles but none of them seem to have the answer that I'm looking for. I already have the tab bar controller and all the sub-views created in the storyboard, I just can't seem to get an instance of the UITabBarController.
I have 2 logical ways of doing it in my mind but I am quite new to objective-c and can't work either of them out for the life of me.
The first is to programmatically load the uitabcontroller and set which item I'd like to load but I can't seem to find a way of invoking an already existing tab bar controller. Something like this (I know it loads a random view which is not what I exactly want):
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:view1ViewController];
My other idea was to either override / hijack the segue or the load event of the tab bar controller and find out who called the segue and then if they are one of my other buttons and then switch to the relevant tab item using:
[myTabBarController setSelectedIndex:index]
I just can't seem to put it all together. I suspect the latter idea requires app delegates which I don't quite understand yet.
I apologise for this in advance - I realise that I'm in completely way over my head! (btw... I have moderate PHP and C# OOP experience so I understand 'some' things.)