Sending info to UIImageView event handler - uiimageview

I'm populating UIImageViews dynamic and have to send some info (at least index: Int) to handler of press event. I've done this before with UIButton easy, while UIButton has a tag property, but how I can do it with UIImageView?

The tag property on UIButton is inherited from UIView. That means UIImageView also has a tag property because it too inherits from UIView.

Related

NSTableView IBOutlet clickedRow is always -1

I have a problem with getting the clickedRow set through IB.
Setup
In IB I have a view with custom class set, call it MyView. The file's owner of the XIB is MyVC.xib. In IB I have also created an NSTableView inside MyView.
Thus the view hierarchy is like so
MyView -> (auto-generated) NSScrollView -> NSClipView -> NSTableView.
The tableview is setup through bindings and connected the double-click action/target correctly, as mentioned in this post Double click an NSTableView row in Cocoa?
I have declared and connected an IBOutlet NSTableView in MyVC.h.
Problem
When the selector is called, the NSArray of objects are passed in nicely. However, I cannot know which of them to operate in since [_tableView clickedRow] always returns -1.

Making a UILabel subview in UIScrollView to be firstResponder

I have added a label with some text and links to an ScrollView,
when you tap on those links (in the label), a delegate method will call, displays a popover and show some related information.
but problem starts from here, I want when you tap on anywhere else except the links, the popover disappear.
if I add a UITapGestureRecognizer to ScrollView, the delegate method for links won't call.
what should I do to label handles the tap on links, and ScrollView Handles the other taps?
I did like that:
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tapped)];
[self.scrollView addGestureRecognizer:tap];
- (void)tapped
{
if ([self.storyText.delegate respondsToSelector:#selector(attributedLabel:shouldFollowLink:)])
[self.storyText.delegate performSelector:#selector(attributedLabel:shouldFollowLink:) withObject:self.storyText];
}
In tapped method Im checking if Im tapping on a link, the delegate should be called, but Delegate wont call.
Am I missing someThing?
You can use custom UIButtons instead of labels or you can place custom UIButtons with clear background color over the links and give actions to this buttons.
Solved!
Solution:
first I create a custom class for my scrollView and subclassed that from UIScrollView.
Second I override
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
in my custom ScrollView class. in this method I called a method to dismiss the popover.
but important part is that in viewWillAppear method of the class which popover will appear, I passed self to custom scrollView class. because if I didn't that, the method for dismissing popover won't work (it needs an object of this class).
[self.scrollView initWithStoryViewController:self];
this images show in which scenario I had this problem:

How to refer to Cocoa controls located in in the same NSWindow?

I have a NSWindow with an NSView and an NSTextField inside.
I'm using Interface builder right now. I have dropped the two controls on the default NSWindow and subclassed an NSView. I'm implementing the -drawRect method from NSView and I need to access to the content of NSTextField.
How do I refer to the instance of NSTextField from a method inside the NSView ?
Your NSWindow is (or should be) controlled by a window controller. In IB you create an outlet for the NSTextField in your window controller. Using the outlet, you can then refer to the NSTextField:
In your window controller .h file:
#property (strong) IBOutlet NSTextField *myTextField;
In your window controller .m file:
#synthesize myTextField;
From there you can in your controller:
[[self myTextField] setEditable: NO];
A point to note is that you do not access the controls in a window directly from that window as windows (and all Cocoa controls for that matter) are statically stored in a XIB/NIB file. All access to controls (UI elements) is channelled through controllers (NSWindowController, NSViewController) which in turn are capable of loading XIB/NIB files.
Apple provides various samples in their docs on how to do this.

UIScrollView subviews and setNeedsDisplay

I've the following problem :
I have a UIView containing a UIScrollView as a subview. (nib file).
Programmatically I add several subviews (UIImageView) to the UIScrollView, each UIImageview contains an image loaded from the net asynchronously, so I need to update the scrollView when the images are downloaded. In the class responsible of the images fetching, I advertise the the View controller responsible to manage the scrollView, using this code
[[(MosaicViewController *)data] scrollView setNeedsDisplay];
the Ivar data is a pointer to the ViewController.
This stuff don't work,no reload of the scrollView happen
To be sure that the call is triggered I wrote a method inside the viewController containing the scrollView, and inside this method I called setNeedsDisplay,
[(MosaicViewController *)data updateView];
-(void) updateView
{
NSLog(#"setNeedsDisplay");
[self.scrollView setNeedsDisplay];
}
the method updateView is triggered correctly, I mean is called after each Image is downloaded, but the scrollView contents isn't updated. In the ViewController containing the scrollView I don't implement the drawRect method, could be this the reason for the lack of update after calling setNeedsDisplay?
Any help/suggestion/reference etc.. is welcome
Thanks in advance
Dude are you doing imageView.image = downloadedImage ??
Also you should not have to do [self.scrollView setNeedsDisplay] since you did not change anything on scrollView !!
What changed is the content of the imageView and imageView.image = downloadedImage will automatically trigger setNeedsDisplay on imageView !!
Some other check points
Is scrollView visible?
Is scrollView.contentSize set??
Is the scrollView frame correct ??

UIView has no events

I want to be able to connect the touchUp event of my UIView to an IBAction, but I can't see any events. I thought that there was a subclass of UIView that did have actions.
Are you sure you aren't looking for the events on UIControl? That is a subclass of UIView.

Resources