Have Multiple UIImageView's From 1 UIImageViews - objective-c

I have declared 1 UIImageView in my code. Is there a way to get multiple out of it? Say for example I have an imageView called red and position that on the screen. Is there a way to have multiple of red on the screen at the one time?
Thanks in advance

One image view is one image view.
If you want more than one, declare more than one.
If you have many similar image views, consider creating one array of many image views instead of a separate property for each one.
If you have all of the image views in a storyboard or .xib file, you can use an outlet collection instead of an outlet to store them.

Related

Repeat a view in Cocoa application

I have the following design:
How should I proceed? Add a NSScrollView with the first element, which contains a couple of NSTextFields and an NSImage and then repeat in the code? What type of repeater should I use? And... is NSScrollView able to handle this type of design?
Is it possible to use NSTableView?
Thank you!
I would probably have a custom NSView class that contains the date labels on the left, a NSImage that toggles between two states (selected or not) and the request label on the right. You can lay it out either in code or in a .nib and instantiate it that way respectively.
When you create the superview create four of the new subclasses and put them in the appropriate places.
Only use scroll view if you think that you'll have so many options that you will need to scroll.

How to add UITableView to one of several subviews using storyboard

I have one UIViewController with two UIViews on it. In the Navigation bar, when one button is pushed one of the UIViews is displayed and when the other button is pushed the other UIView is displayed. I want to put a UITableView on one of the views. However, the UITableView requires the UIViewController to use the UITableViewDelegate and UITableViewDataSource. Having implemented this for my UIView (subview) containing the UTTableView, when I click on the button for the other view, which does not contain a table, I get errors and the application croaks.
I am assuming (possibly incorrectly) that my issue is that I am trying to use the same UIViewController for both subviews, but only one contains a table.
Question 1) Is it possible to do what I described above? Meaning, if I had a problem then something was not connected up correctly.
So, I went down a path of creating two separate UIViewControllers; one for each view. Not sure this is the smart approach. Now I am just looking for advice on the best way to do this. Thank you in advance for your help.
To be more clear about what I am trying to do. I want the blue view to be put where the pink view is when the first button on the bar is clicked and I want the yellow view to be put where the pink view is when the second button is clicked. Essentially the pink view will never be displayed and may not even need to be on the UtilityViewController.
Having each as a UIViewController (or a subclass thereof) is the way to go about what you are trying to do. The UITabBarController does this already: https://developer.apple.com/library/ios/documentation/uikit/reference/UITabBarController_Class/Reference/Reference.html

How to change size of UICollectionViewCell inner elements?

I've got a UICollectionView with 3 custom views inside each UICollectionViewCell. I need to make these 3 views bigger in one cell, but I couldn't find a way to access size properties of these views. Is there any way to do it?
Thank you in advance.
If you're subclassing UICollectionViewCell, you can resize them in layoutSubviews. If you're building the cell in your controller, you can assign the subviews a tag, and get them later using viewWithTag:.

Best way to implement "iOS Photos style" tiled image gallery

I have an app that basically can be used to download, upload, and manage photos from various web services.
I want the image list view to look like the iOS Photos app but not quite sure what the best way to do that is.
I was thinking I could use NSMutableArray and subclass UIScrollView to create that functionality from scratch but I'd really like to use NSFetchedResultsController because some of the data related to the images are dynamically/asynchronously updated/inserted/deleted in Core Data.
Right now I've setup something pretty hacky.
I created an separate Core Data entity to hold relationships to 4 photos in each managed object and I made UITableView loop through them. Then cellforrow delegate would loop through the 4 photos in each table cell. This approach sucks because it's hard to delete and insert photos dynamically and I have to reconstruct relationships and reload the table each time an update is made.
I've looked at some other libraries that do this but I really want to understand what the most simple and efficient way to do this is.
If you are referring to the tile view, you can duplicate that using a UITableView or a UIScrollView. If you want it to side scroll then a UIScrollView is the starting point.
If you want it to scroll vertically (which I recommend on iPhone) then use a UITableView with a custom UITableViewCell.
As for the Core Data side, you are probably coming at this incorrect, you are trying to store UI state information (how many photos are in a cell) in core data. Core Data should not care about how many images are in a cell.
UITableViewCell
To use a UITableView you would create an array that contains all of your images. You can then determine how many rows you need by dividing that array by the number of images per row.
From there you should subclass UITableViewCell and pass in the 4 images for that cell to draw. Then it is a simple matter of adding 4 UIImageView instances to the custom cell and setting the images.
UIScrollView
For a scrollview you crate a UIImageView for each image and then add them as subviews of the UIScrollView. You would then set the frame of each UIImageView so that they are displayed in a grid.
If you find you have more images than you can hold in memory at once then you will need to deal with tiling, effectively paying attention to where the user is scrolling and filling in (via moving the offscreen image views) ahead of the edge the user is scrolling towards. This is the same thing you get effectively for free with a UITableView via its queuing of cells.
I just did this with a UITableView - you are over thinking it with the relationships.
For my solution I created a UITableViewCell subclass has four buttons as properties.
In my cellForRow method I figure out which four images belong to that row and then set the appropriate image for the appropriate button.
My images are in an array in my view controller. I populate the array in viewDidLoad. Whenever I add or delete an image from the managedObjectContext I repopulate the array and then reload the tableview. Reloading the tableview will rearrange the images in the cell appropriately.
Scrolling is smooth and the only drawback I have run into is that I would like the images to animate to their new positions when I delete one, but I do not think that I'll be able to pull that off with this setup.
I think a very nice implementation is AQGridView.
It is easy to extends, has nice reordering (see the springboard demo) and it reuses the cell.
If you ever implemented a TableViewDelegate, you should be able to use it.
You should check out the Three20 photo viewer. The project is on github. Also, there's a nice tutorial for the photo viewer here

How do I share an NSArrayController between two nib files?

I have an array of images, and two nib files. One nib file has a window that displays the images in an NSTableView. The other nib has a window that draws the array of images into an NSView, and also draws a highlight over the images that are selected.
The array of images is controlled by an NSArrayController. I'm having trouble getting the two nibs to share the NSArrayController. I would have two separate NSArrayControllers bound to the same content, but I also want both nibs to share the controller's selection; that is, if you select an image in the table window, it also becomes selected in the other window.
Is there a standard way to do this?
I would have two separate NSArrayControllers bound to the same content, but I also want both nibs to share the controller's selection; that is, if you select an image in the table window, it also becomes selected in the other window.
Is there a standard way to do this?
Have two separate NSArrayControllers bound to the same content and selection indexes.