I have created multiple imageViews within one custom cell. How do I target to update a specific image view within the NIB?
I have given it a restoration ID, can I access it using this?
I guess you can use the tagging for that...to distinguish one view from another
https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSView_Class/Reference/NSView.html
find the tag method here
Setting up the imageview as an outlet so i could then reference it worked
Related
I am developing an iOS application and I have, in one of my controllers, an outlet collection of UIImageView.
Each imageView inside has a different tag. Only when I loop over the collection to get their tag, only the tag of the first element I added inside appears..
Here is the relevant part of the code :
#IBOutlet var imageLine1: [UIImageView]!
for image in tabImage {
print(image.tab)
switch image.tab {
// Here I do some stuff
}
}
And now the display in the Xcode terminal :
6
And the first image I added to this table has a tag of 6. So I conclude that I didn't manage to add the other images (which I do with a control drag on the outlet collection).
Does anyone have any idea what the problem is/ how to fix it?
Namely that I already had a similar collection, which contained all the images, which I deleted to replace it with the one above. They had the same name and the same elements inside, maybe that interfered with the correct functioning.
Thanks for your help!
When you delete the old outlet collection you have to reconnect them to the new outlet collection within Interface-Builder.
Also make sure to delete the references to the old outlet connection within IB.
I've created a new xib by New File->View. So, I put a name for my class which is a child of UITableViewCell.
But in the next inlay there is no option of where to put in a reuse identifier.
I tried this several times and it's all the same. Could anyone suggest me how to fix it?
create UITableViewCell like this bcs you take the uiview and extend the tableviewcell class
see second image you have UIView not cell
it looks like you selected something else, Not TableViewCell
Please see below screenshot
If you have want to set Reuse Identifier for cell, then must use cocoatuch file with xib select see below image. You can't create seperate xib, coz xib file have no any property like Reuse identifier.
Im facing a problem with adding a UIImageView to a single UITableViewCell. I add the subview like this in the cellForIndexPath delegate method which is ONLY added to the cell if the self.mediaTypeArray contains the string: "Image" at the index: indexPath.row
let cell = self.timelineTableView.dequeueReusableCellWithIdentifier( NSStringFromClass(ClassicCaseCell), forIndexPath: indexPath) as? ClassicCaseCell
if self.mediaTypeArray[indexPath.row] == "Image" {
let imageView = UIImageView()
imageView.frame.size = (cell?.evidenceView.frame.size)!
imageView.frame.origin = CGPointZero
imageView.image = img
cell?.evidenceView.addSubview(imageView)
}
Which it works great however, I find that every other two cells contains that same imageView even when self.mediaTypeArray[indexPath.row] is NOT equal to "Image" and I don't understand why. I think it may have something to do with reusable tableviewcells but I still don't see why it would do this. Please help!
I'm getting the feeling that this is because of cells being re-used.
A way you can work around this is to override your ClassicCaseCell's prepareForReuse method to remove any image view from its evidenceView.
I would however recommend that you don't add the image view in this fashion (through the delegate's cellForIndexPath method). Instead, your ClassicCaseCell should hold the image view as an instance variable which you can then set in cellForIndexPath. This way, there is only at most one. You can also make sure to set the image view to be nil in prepareForReuse, making sure that it won't appear in the cell if it is not set.
First, don't use tag property as recommended elsewhere. That was a technique used a long time ago, but Apple discourages that practice now. Second, I'd suggest you simplify your life and simply don't programmatically add image views in cellForRowAtIndexPath. If you programmatically add image views, cell reuse introduces a clumsy process of determining whether (a) you need an image view; (b) whether there is an existing image view; and (c) possibly adding/removing image view and/or getting reference to existing one.
One very simple solution is to just have two cell prototypes, one with an image view and another without. Then, based upon the media type, dequeue a cell with the appropriate storyboard identifier and use it.
The other alternative is to have the image view in the cell regardless, and hide/show it as appropriate. The challenge then becomes how to best manage two sets of the constraints, one for when the image view is visible and one when it's not. You can do this with judicious choice of constraint priorities, activating/deactivating the appropriate constraints in cellForRowAtIndexPath, etc. It can be done, but this is more cumbersome than the above approach, whereby you just employ two cell prototypes.
You only need to add the UIImageView once so if the cell is re-used again, it (might) already be there. Your problem is to detect if you've already added it or not. Here are a couple suggestions:
1) ALWAYS create it (and just don't set the image, or hide it)
2) assign it a unique tag and look for the tag when you need to set it... no tag, then create it
Override prepareForReuse delegation in your tableview cell and remove imageview from there
I have that view object with some elements. I want to call that view , and can use it in another view, having a list of objects view one below the other. The problem, I do not know how I can create like a component.
Regards
Create a subclass of UIView, and do what you need to in the view, and every time you want to use this kind view, just use an instance of this class.
I think you want to use a reusable UIView, so in your case I think you will create a xib in Xcode.
Regards, Jorge.
Have a look to Container view in interface builder
I'm creating a Table View in Interface Builder (Storyboard). I'd like to have a couple of different Dynamic Prototype cells with different sets of Labels and Images in them and so on, and I can give them different reuseIdentifiers so I can pick which ones I want at runtime.
In Interface Builder, I create several Dynamic Prototype cells in my UITableView, which is controlled by a UITableViewController.
In the first cell, I drag and drop in various views and so on.
In the second cell, IB will not let me drag any views into it? I can resize the second cell vertically, but can't put anything into it at all, either by dragging into the cell or into the object graph in the left-side bar.
If I copy and paste the first cell, a second Dynamic Prototype will appear with all of the same contents, but I won't be able to modify the copied cell (can't add or move subviews). However--and this is strange--I can select the constraints and modify their values to resize and shift objects in the second cell.
As a note, running XCode 5-DP3. Tried restarting it (didn't expect that to help, and it didn't). Otherwise, unsure what to try, and unsure if I'm doing something very braindead, or if this is a bug I need to report to Apple.
So, am I crazy? Has anyone experienced this/can anyone recreate this?
EDIT:
After further testing, if I stick a big UIView into the first cell, and then copy that cell, I can edit inside my added view. (Does this make sense?) I can't edit anything that lies within the second UITableViewCell, but if it contains a UIView copied over from the first cell, I can put new views into that view and move them around and so on. Super-strange.
For the sake of posterity, I'm answering my own question:
The way I solved this was to take a UITableViewCell object from the Object library and drag it onto the UITableView. Sounds simple, right?
The problem I was running into was only if I copied existing dynamic prototypes through Cmd+C & Cmd+V, or by incrementing the number in the Attributes inspector for the table view. The Storyboard Editor wouldn't allow me to modify those ones.
Dropping in new cells from the Object library let me tweak them all separately.
XCode 5-DP6 solved issues with not abling to resize cell's subviews.