Reputation: 5545
I Have create a Static library /Framework using this tutorial
For calling a view class customView **( type UIView )**we used below code
-(void) showMessageInViewController:(UIViewController *)viewController {
if (_isEnabled) {
NSBundle* frameworkBundle = [NSBundle bundleForClass:[self class]];
CustomView *csView = [[frameworkBundle loadNibNamed:@"CustomView" owner:self options:nil] firstObject];
csView.frame = CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height);
[viewController.view addSubview:csView];
}
}
My Question is :
If i create a UIViewController Class inside my Framework then how i navigate or call it using my Class
-(void)showMessageInUIViewController:(UIViewController *)uiviewController
{
DetailViewController *viewController = [[DetailViewController alloc]
initWithNibName:@"DetailViewController"
bundle:nil];
viewController.delegate = self;
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:viewController];
[self presentModalViewController:navController animated:YES];
}
It shows error in .delegate and presentModalViewController
Upvotes: 0
Views: 896
Reputation: 2818
You can Use Have a reference to the UIViewController
that you uses your framework currently.
in InsertManager.h
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface InsertManager : NSObject
+(instancetype) sharedManager;
-(void) setViewController; // the view controller will use it to assign itself to the framework.
-(void) startManager;
-(void) stopManager;
-(void) showMessageInViewController:(UIViewController *)viewController;
-(BOOL) isManagerRunning;
@end
in InsertManager.m
#import "InsertManager.h"
#import "CustomView.h"
@interface InsertManager()
@property (nonatomic) BOOL isEnabled;
@property (readOnly) BOOL hasViewController;
@property (nonatomic, weak) CustomView * csView;
@end
@implementation InsertManager
+ (instancetype) sharedManager {
static InsertManager *sharedManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedManager = [[[self class] alloc] init];
// create the custom view only once.
NSBundle* frameworkBundle = [NSBundle bundleForClass:[self class]];
_csView = [[frameworkBundle loadNibNamed:@"CustomView" owner:self options:nil] firstObject];
csView.frame = CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height);
});
return sharedManager;
}
-(Bool) hasViewController {
return _viewController != nil;
}
- (void) setViewController:(UIViewController *) viewController {
_viewController = viewController
// add the views you want to it all at once, but keep them hidden.
_csView.hidden = YES;
[_viewController.view addSubview:csView];
}
- (void) startManager {
NSLog(@"Manager is running");
_isEnabled = YES;
}
- (void) stopManager {
NSLog(@"Manager stopped..");
_isEnabled = NO;
}
-(BOOL) isManagerRunning {
return _isEnabled;
}
-(void) showMessage {
if (_isEnabled && _hasViewController) {
// Only unhide the custom view as its already added to the _viewController and hidden.
_csView.hidden = NO;
}
}
@end
CustomView.m
#import "CustomView.h"
@implementation CustomView
- (IBAction)closeButtonClicked:(id)sender {
// [self removeFromSuperview];
self.hidden = YES;
}
@end
I hope this helps. It might needs a bit of tweaking as I just wrote it here(no compilier). Thanks.
Upvotes: 1