Changing UILabel text from UICollectionView custom delegate class - objective-c

In my storyboard I have a UICollectionView, with cells, sections, etc. I set as delegate and datasource a custom class (so, not the classic myCollectionView.delegate = self) but a custom class that cares about the retrieving of datas.
In this UICollectionView I have a label that I need to update with a certain value that I handle in the delegate class. (It's a property of the selected cell).
How can this be done? I read about KVO and Notification, but i'm not sure what I have to do.
More Detail
MatchCollectionViewController
In this one:
viewDidLoad
A gameView that act as a container for the following collectionView
CollectionView declaration (once created the collectionView i add it to the gameView)
The delegate of the CollectionView is the following class CollectionViewUiGrid
CollectionViewUiGrid
In this class i implement all the delegate and dataSource methods for the collectionView
initWithFrame (and initWithFrame with my own parameters)
in the method cellForItemAtIndexPath i return an istance of a class (UiGameCell) that extends UiCollectionViewCell
In the method didSelectItemAtIndexPath i have this logic.
If a cell is selected, assign retrieve his property, called CellDescription).
This is the property that i would like to be as my UiLabel value in MatchCollectionViewController.

I found a solution.
As mentioned in
Pass object with NSNotificationCenter to other view
Probably one of the simplest way is to use a NsNotificationCenter.

Related

How do I have a subclassed UIGestureRecognizer class call a selector on a view

I have a view called GameViewController. I didn't set it up but it seems to be a UIKit view with an embedded EAGL view.
I set up gesture recognizers for tap and swipe on my GameViewController. They work great, except the method I set up as a selector for tap (a function within GameViewController) gets called on touchesEnded, not touchesBegan.
Only way to get at the touchesBegan function is to subclass.
So, I subclassed UITapGestureRecognizer, created a touchesBegan function, and NSLogs in there get called on touch down. However, I can't call any functions in GameViewController from the UITapGestureRecognizer subclass. (Class method +METHODIWANTTOCALL not found).
I realize I need "references" back and forth but what should they be? Or is this totally the wrong approach? Do I delegate? (I'm new to that) What is the best way to have a method within GameViewController called from this UITapGesture subclass?
It seems like your GameViewController is a singleton class (only one instance of this class in the app). You can have a class method in GameViewController that returns the instance of the singleton. Then you can just the method regularly:
In Recognizer:
GameViewController* myController = [GameViewController getInstance];
[myController handleTouchBegin];
Alternatively, you can define your handleTouchBegin as a class method if it does not need to know any internal state:
[GameViewController handleTouchBegin];

Handling custom selection style in view based NSTableView

How do I go about drawing my own custom selection style for a view based NSTableView? I tried putting a BOOL var in my NSTableCellView subclass and set that to YES if it is clicked and then I can successfully draw my custom selection. But how do I change that BOOL var to NO when another view is clicked? Thanks for any help.
EDIT: After reading through the NSTableView docs, it looks like I need to subclass NSTableRowView to override the selection drawing, but what do I do with my NSTableRowView subclass? How do I get the table to use it?
Alright, I figured it out. You just have to subclass NSTableRowView. It has methods for drawing the background for selected and deselected rows. To get the table view to use your subclass just implement the table view delegate method tableView:rowViewForRow: and return an instance of your subclass.
To make things clear, I think we should give the code of the delegate method :
- (NSTableRowView *)tableView:(NSTableView *)tableView rowViewForRow:(NSInteger)row
{
MyNSTableRowView *rowView = [[MyNSTableRowView alloc]init];
return rowView;
}

How do I edit the same UILabel in every row of a TableView

I have TableView with a custom TableViewCell loaded from an external nib file. Each cell has a UILabel that needs to be hidden each time the edit button is pressed in the parent Navigation Controller.
Is there a UITableViewDelegate or UITableViewDatasource protocol method that I can use that will let me change the alpha level or employ the setHidden property on each and every visible UILabel from each instance of the TableViewCell (e.g., for all indexPath.row)?
Thanks!
[tableView visibleCells] returns an array of all the cells that are visible at the moment. In your tableViewController's setEditing method you can use this to configure the existing cells.
You will also need to modify your cellForRowAtIndexPath method so that newly dequeued cells have the label set to visible / invisible as appropriate, depending on tableView.editing.
If your cell was a custom subclass you could override setEditing: animated: and make the changes there .

Get Index of Object in TouchesEnded

i have a UIViewController with many UIImageViews. I need in touchEnded event get a index of this UIimage.
How do Make?
Thank's
make a custom UIImageview class which is subclass of UIControl. and add a target method for this class.set the tag for each UIImageview. and change the class name of UIImageview in inspector window to that custom class.
[imageview addTarget: self action:#selector(findIndex:)forControlEvents:UIControlEventTouchUpInside ]
you can set this method using xib also.
and define findIndex method in your viewController class.
Instead of UIImageViews, why don't you use UIButtons? You can set the image with setImage:forState:, and the target action and object with addTarget:action:forControlEvents. When your target action gets called, the button will be sent as the sender argument.

Loading Accessory callout view for mkannotationview

I have a map annotation view that contains a rightcallout button which loads an accessory view which is a UIViewController class. I am using resuable annotations, but am wondering how I can pass updated information to my UIViewController class. Let's say I have 2 string values which map to 2 UILabels on my view. How can I update those values after the initial accessory view has already been loaded into memory as a resusable view?
Any help would be appreciated.
You'll need to maintain a reference to the UILabels in the object that gets the update, and then use setTitle: (I think) to update the labels.
In your annotation subclass you need to override the setTitle method to send the changes to the instance of your UIViewController class that your subclass is holding. Or, you could setup your annotation subclass to receive notifications (from NSNotificationCenter), and upon receiving a notification, update the title and the instance of your UIViewController class.
If you are unfamiliar with NSNotifications, then here is a quick reference. I used these to keep my annotations updated.
NSNotification Example
Try using the MKMapViewDelegate method:
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control;
This method is called when a user tapped one of the annotation view’s accessory buttons. Assuming that your MKMapViewDelegate is also the UIViewController that can access your accessory view.