iOS library: how to use the delegate function - ios

I have to use a library for my iOS project.
the library offers the class ICDevice (abstract) with a delegate ICDeviceDelegate.
the ICDeviceDelegate offers the following funtion
-(void)accessoryDidConnect:(ICISMPDevice *)sender;
I want to integrate this function in my ViewController to detect when the device is connected. How to do that?

Go to your .h and set your controller as delegate of the library #interface YourViewController : UIViewController <LibraryDelegate> so then you will be able to set your view controller as delegate when creating the library object
YourLibrary *library = [YourLibrary new];
library.delegate = self;

Delegates are a very important pattern in Cocoa/CocoaTouch, I suggest you read Apple's documentation to get a good grasp on it.
Once you understand them properly, it should be trivial to figure out the answer to your question.
Documentation

Related

implement delegation from a viewController to a DataManager class

I need to send an object (data) from a view controller (embedded in a navigation controller) to a class (or struct) which should manage this data.
How can I get a reference to this viewController from the class (which has no link of any kind (no segue), or better the struct) with the set of viewControllers in order to implement a delegation protocol?
I use swift, a storyboard, and I look for any pointer or documentation which could help me to understand how to address this problem. I'm a beginner and I am sorry if this question is far too trivial.
I just need a link to appropriate documentation, many thanks.
This answer might help you. You might wanna read up more on delegation pattern in iOS.
https://stackoverflow.com/a/42977875/2396199

Send image from Objective VC to Swift configured VC

I am working on a project which somewhere needs to send the edited image to another ViewControler using segue or storyboard.
Some points to understand first.
The ViewController i am sending image which is configured using Objective C.
And the image is to be pass that ViewController which is configured using Swift Lang.
Problem:
The Swift Class which is imported in Objective .m file is not visible so it lets me to create its object to make reference of its members.
I tried:
// here i am not able to create SwiftVC class object so i can pass image further
SwfitVC *object = [self.storyboard instantiateViewControllerWithIdentifier:#"VC_Identifire"];
object.image = image;
[self.navigationController pushViewController:object animated:YES];
SwftVC Class is not visible after importing to .m file.
Please have look. Thanks.
In order to make your Swift file visible; in your .m file you'll have to write this import statement.
#import "YourProjectName-Swift.h"
Clean and build then you'll be able to use your Swift class.
Alternate way:
You can save the image to Document Directory in Objective-c class and fetch it into Swift Class.
Might be a help this logic.

Modify behaviour of viewDidAppear in UIViewController

I have application (UICatalog from Apple samples). I am using it with a framework called Lookback which is intended for screen recording.
I have interface defined as follows:
#interface AAPLSteppperViewController : UITableViewController
So it is in a straight way a subclass of UITableViewController. And it has implemented a methods as follows:
+ (NSString*)lookbackIdentifier {
return #"Profile Editor";
}
I wanted to investigate how lookbackIdentifier is being called and see something like that:
The question is: how to introduce such behavior as UITableViewController is a system class and I am not able to see the source of calls numbered 1 and 2 at the stack?
As I investigated framework docs, they recommend to implement always like that
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
...
}
As for me it looks like a change inside UIViewController - but how to achieve something like that?
I guess that it will include some playing with UIViewController but - how? I can't imagine how to override a single method of it without subclasssing.
I have only access to my AAPLSteppperViewController.
I would be grateful if somebody could give me a push in the right direction
As #dan pointed - swizzling is the right answer. I tried with instructions there: http://nshipster.com/method-swizzling/ and it gave me desired behaviour.
Thanks for help :)

UIpicker view data source

I'm a IOS noob and I'm trying to understand how to set the datasource of of the uipicker view
i have followed This tutorial, everything seems to work correctly however i get a warning in xcode that says
'id<UIPickerViewDataSource>' from incompatible type 'StateViewController *const __strong'
it occurs on this line.
myPickerView.delegate = self;
I keep trying different things but they all lead me in the same direction. It fails.
How should i be doing this? how to i properly set the datasource of a UIpicker view.
Thanks in advance for your guidance.
You just need to tell the compiler that you're going to conform to the delegate protocol. You do that by adding <UIPickerViewDataSource> to your .h file,
#interface StateViewController : UIViewController <UIPickerViewDataSource>
You need to say
myPickerView.dataSource = self
and also
<UIPickerViewDataSource>
Step 1: Add UIPickerViewDataSource delegate in your header file
#interface StateViewController : UIViewController <UIPickerViewDataSource>
Step 2: Now add the following line in your class file
myPickerView.dataSource = self

Making a TableViewController a subview of a TableViewController (ios)

I am trying to add pull to refresh to my app and am using the Pull to Refresh files here: https://github.com/leah/PullToRefresh However I am confused on how to make a subclass of my table view. How does one do that?
You mean something like this?
#interface MyTableViewController : PullRefreshTableViewController
{
//Member variables here.
}
// Methods and protocols here.
#end

Resources