delegate method not working on SWRevealViewController - ios

i want to refresh my main view on slide menu did select method with categorically
i have used SWRevealViewController to load my slide menu and its working fine but i cant understand how to assign delegate to the slide menu controller and use it?
here is the link for awesome library by john lusch
slide menu controller.h
#protocol SlideViewControllerDelegate
#required
-(void)menuViewControllerDidFinishWithCategoryId:(NSInteger)categoryId;
#end
#interface SlideViewController :
UIViewController<UITableViewDataSource,UITableViewDelegate>
{
__weak id<SlideViewControllerDelegate> slideDelegate;
}
#property (nonatomic, weak) id <SlideViewControllerDelegate> slideDelegate;
#end
slide menu controller.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.slideDelegate menuViewControllerDidFinishWithCategoryId:indexPath.row];
}
viewController.h
#interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate,SlideViewControllerDelegate>
viewController.m
in my view did load method
SlideViewController *slideView = [[SlideViewController alloc]init];
slideView.slideDelegate = self;
- (void)menuViewControllerDidFinishWithCategoryId:(NSInteger)categoryId
{
self.categId = [catIdArray objectAtIndex:categoryId];
NSLog(#"cat id %#",categId);
[self getQuestions];
[self.feedTableView reloadData];
}
//Log above is never executed
so i think may be i am wrong with assigning delegate to the swreveal view controller slide menu

got it to set a delegate to a reveal controller do like this
[(SlideViewController *)self.revealViewController.rearViewController setSlideDelegate:self];

Maybe you should init SlideViewController by
- (id)initWithRearViewController:(UIViewController *)rearViewController frontViewController:(UIViewController *)frontViewController;
which says in the README.md.

Remove that lines:
{
__weak id<SlideViewControllerDelegate> slideDelegate;
}
Your property:
#property (nonatomic, weak) id <SlideViewControllerDelegate> slideDelegate;
it's enought.

Related

Trying to dismiss a popover view controller with a table view inside of it

I'm trying to dismiss a popover when selecting a cell inside of it.
I have created a custom delegate to support this however it is not working:
In my class that houses the PopOver and table View I have the following:
In .h:
#protocol DismissDelegate <NSObject>
-(void)didTap;
#end
#interface AssistanceNeededAtPopOverViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>
#property (nonatomic, assign) id <DismissDelegate> delegate;
In .m:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self.delegate didTap];
}
In .h of the viewcontroller where the popover lives in:
#interface GlobalPageSideDetailViewController : BaseViewController <UITextFieldDelegate, UIAlertViewDelegate,UIPopoverControllerDelegate,DismissDelegate>
and in .m:
AssistanceNeededAtPopOverViewController *classpop = [[AssistanceNeededAtPopOverViewController alloc]init];
classpop.delegate = self;
-(void)didTap{
if (self.assistanceNeededAtPopover != nil) {
[self.assistanceNeededAtPopover dismissPopoverAnimated:YES ];
self.assistanceNeededAtPopover = nil;
}
}
this should be read and the popover should be dismissed...any help would be appreciated...
You have to set the delegate of your AssistanceNeededAtPopOverViewController that pops the controllerview, as the new GlobalPageSideDetailViewController.
Here you're setting the delegate of a controller you just instantiate and not the one which poped the controller.

IOS In UIPopoverController using category for popup to Home view controller data send but its not working

I have create one Home view controller and open popup on one button the popup view is one another controller this controller name is "DetailViewController" and in view controller i have create one tableview and this tableview "didSelectRowAtIndexPath" method i have call one delegate method but here is delegate method is nil and not call a function
Here is my code please give me solution
Protocall
MonsterSelectionDelegate.h
#protocol MonsterSelectionDelegate <NSObject>
#required
-(void)select_protocol:(NSIndexPath *)getIndexpath;
#end
Home View Controller.h file
#import <UIKit/UIKit.h>
#import "MonsterSelectionDelegate.h"
#interface HomeViewController : UIViewController<MonsterSelectionDelegate>
-(IBAction)click_pressme:(id)sender;
#end
Home view controller .m file
-(void)select_protocol:(NSIndexPath *)getIndexpath
{
NSLog(#"dsfsdfsdfsdfsdfsdfsdf");
}
Detailview controller .h file using for popup
#import <UIKit/UIKit.h>
#import "MonsterSelectionDelegate.h"
#interface DetailViewController : UIViewController<UITableViewDelegate,UITableViewDataSource,MonsterSelectionDelegate>
#property (nonatomic , retain) NSArray *TheAry;
#property (nonatomic, weak) id<MonsterSelectionDelegate> delegate_view;
#end
Detailview controller .m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(#"%#",self.delegate_view);
if (self.delegate_view) {
[self.delegate_view select_protocol:indexPath];
}
}
didSelectRowAtIndexPath delegate view is null please give me solution where i do mistake please help me

Moving to and fro modal view inside TabBarController

hi i am working on an app and all was going good till now.... i am stuck at this point..
here is my storyboard snapshot..
in the DemoTableViewController when i clock on "filters" button .. Brands TableViewController is opened modally .
after user select multiple rows in Brands TableViewController ,, he then clicks on done button and view controller is dismissed by this code:
-(IBAction)DonePressed:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
I am storing the user selections in NSMutableSet and it is to be Used in DemoTableViewController so that i can reload the table rows according to the selection but i dont know how to send NSMutableSet to DemoTableViewController and then reload the table according to selection..
what is the right way to dismiss modal view and reload the parent DemoTableViewController
i know i am not doing it correctly but can anyone help me in doing it...
here is some code ---
DemoTVC.h
#import <UIKit/UIKit.h>
#import "MyModelClass.h"
#import "brandsTableViewController.h"
#interface demoTableViewController : UITableViewController<UITableViewDataSource,UITableViewDelegate,MyModelProtocol,FilterProtocol>
#property (strong, nonatomic) IBOutlet UITableView *demoTable;
- (IBAction)FilterPressed:(id)sender;
#end
DemoTVC.m--
the method which performs segue--
- (IBAction)FilterPressed:(id)sender {
[self performSegueWithIdentifier:#"FilterPressed" sender:self];
}
the delegate method which is called to get the values from BrandsTVC--
-(void)GetTheSet:(NSMutableSet *)MySet{
[self dismissViewControllerAnimated:YES completion:nil];
}
viewdidLoad--
- (void)viewDidLoad
{
[super viewDidLoad];
productArray = [[NSMutableArray alloc] init];
homeModel = [[MyModelClass alloc] init];
// Set this view controller object as the delegate for the home model object
homeModel.delegate = self;
// Call the download items method of the home model object
[homeModel downloadItemswithurl:#"url is written here"];
}
BrandsTVC.h---
#import <UIKit/UIKit.h>
#import "MyModelClass.h"
#protocol FilterProtocol <NSObject>
-(void)GetTheSet:(NSMutableSet *) MySet;
#end
#interface brandsTableViewController : UITableViewController<UITableViewDataSource,UITableViewDelegate,MyModelProtocol>
#property (strong, nonatomic) IBOutlet UITableView *RetailerList;
#property (strong,nonatomic) NSMutableSet *selectStates;
#property (nonatomic, weak) id<FilterProtocol> delegate;
- (IBAction) DonePressed:(id)sender;
#end
BrandsTVC.m---
#interface brandsTableViewController ()
{
MyModelClass *myModelClass;
NSMutableArray *BrandsArray;
brandsTableViewController *Delegate;
}
#end
viewDidLoad----
- (void)viewDidLoad
{
[super viewDidLoad];
BrandsArray = [[NSMutableArray alloc] init];
self.selectStates=[NSMutableSet new];
myModelClass = [[MyModelClass alloc] init];
// Set this view controller object as the delegate for the home model object
myModelClass.delegate = self;
// Call the download items method of the home model object
[myModelClass downloadItemswithurl:#"url to get json"];
self.tableView.allowsMultipleSelection = YES;
}
Done Button is called ---
- (IBAction)DonePressed:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
id<FilterProtocol> strongDelegate = self.delegate;
if ([strongDelegate respondsToSelector:#selector(GetTheSet:)]) {
[strongDelegate GetTheSet:self.selectStates];
}
}
#end
You can keep those elements in NSUserDefaults, and whenever DemoTableViewController appears, you send [tableView reloadData]. Do this in the viewDidAppear: method.
You can also use Core Data, but there are a lot of details to explain how to do that.
After a lot of trial and error i come to know that in BrandsTVC--
- (IBAction)DonePressed:(id)sender {
NSLog(#"done pressed %#",self.delegate);
[delegate GetTheSet:self.selectStates];
}
self.delegate is giving me NULL.
delegate is not setup and i cant figure out how to do that.. someone help me..
this answer solved my problem :D
custom viewcontroller delegate not working

Set up Protocol with Modal View Controller -> ViewController

I have an initial ViewController, lets call it HomeViewController, that has a button which calls a modal view controller, lets call it ModalViewController. Inside that ModalViewController I have a table view with two sections. If you click on any cell from section 0 it sends information back to HomeViewController (this part I have working with Protocol). If you click on any of the cells from section 1 it pushes to another view controller with options, lets call it OptionsViewController. Here is where it gets tricky for me. If you click any of those options, dismiss OptionsViewController and close ModalViewcontroller and send that information to HomeViewController, just like ModalViewController to HomeViewController. I have tried to set up a protocol similar to the one in ModalViewController but it is never called.
OptionsViewController protocol & .h file
#protocol OptionsViewControllerDelegate <NSObject>
#optional
-(void) optionsInfo:(NSArray *)optionsViewArray;
#end
#interface OptionsViewController : UITableViewController
#property (retain) id delegate;
#property (nonatomic, strong) NSArray *sendArray;
#end
OptionsViewController.m where it's called to pop off the stack.
{
[self dismissOptionsView];
}
-(void) viewWillDisappear:(BOOL)animated
{
NSLog(#"Send Array: %#", self.sendArray);
[[self delegate] optionsInfo:sendArray];
}
-(void)dismissOptionsView
{
[self.navigationController popViewControllerAnimated:YES];
}
Inside ModalViewController.h
#protocol ModalViewControllerDelegate <NSObject>
#optional
-(void) sendInformation:(NSArray *)infoArray;
#end
#interface ModalViewController : UITableViewController <ConditionsViewControllerDelegate, UISearchBarDelegate>
{
UISearchBar *searchDrugBar;
}
#property (retain) id delegate;
#property (nonatomic, strong) IBOutlet UISearchBar *searchDrugBar;
#property (nonatomic, strong) NSArray *infoArray;
#end
ModalViewController.m where OptionsInfo is supposed to come in.
-(void) optionsInfo:(NSArray *)optionsViewArray
{
//IT NEVER REACHES HERE :(
NSLog(#"HERE");
self.infoArray = optionsViewArray;
NSLog(#"Finished");
[self dismissViewControllerAnimated:YES completion:nil];
}
Has any one has done something similar like this or knows the solution to this? Any information, link, guidance and etc. to the right direction will be appreciated. Thanks in advance.
You need to set the delegate in your OptionsViewController below:-
In your OptionsViewController.m Include below line on your method
[self setDelegate:ModalViewController];

how to pass data from tableview to another tableview cell?

I am using static UITableView to show profile of a customer.
It has SelectCountryCell to select country which, when clicked, opens new UITableView with country list.
When I select country from Country TableView, It should display in previous TableView's SelectCountryCell.
How do I do this?
You should bind the static cells to outlets in your UITableViewController and put the profile syncing methods to the - viewWillAppear method.
When the user changes the country in the Country list the profile updates. After that when the user moves back to the UITableViewController instance with static content the profile data will be automatically updated.
You can define a delegate in your CityTableView and then define a method in this delegate.
You should realize this method in your CountryTableView.
Then you may get what you want.
I only offer you a thought. You should find the detail by yourself.
MasterViewController.h
#import "DetailViewController.h"
#interface MasterViewController : UITableViewController <DetailProtocol> // Note this.
#property (strong, nonatomic) DetailViewController *detailViewController;
#property (strong, nonatomic, readwrite) NSString *selectedCountry;
#end
MasterViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (!self.detailViewController) {
self.detailViewController = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:nil];
}
self.detailViewController.delegate = self; // THIS IS IMPORTANT...
[self.navigationController pushViewController:self.detailViewController animated:YES];
}
// Note this -- It's a delegate method implementation
- (void)setCountry:(NSString *)country
{
self.selectedCountry = country;
}
DetailViewController.h
#protocol DetailProtocol <NSObject>
-(void)setCountry:(NSString *)country;
#end
#interface DetailViewController : UIViewController
#property (strong, nonatomic) IBOutlet UITableView *tableView;
#property (unsafe_unretained) id <DetailProtocol> delegate; // Note this
#end
DetailViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
[self.delegate setCountry:[countries objectAtIndex:indexPath.row]]; // Note this
[self.navigationController popViewControllerAnimated:YES];
}

Resources