Reputation: 17
hi i tried to create a delegate to backpass data from tableInterval to ElectricMeter uiViewController but stil the delegate won't fire. this is my code tableInterval h.file
@protocol updateIntervalDelegate
@required
-(void)intervalRefresh:(NSString *)interval;
@end
@interface tableInterval : UITableViewController<UITextFieldDelegate, MBProgressHUDDelegate>
{
IBOutlet UILabel *IntervalLabel;
IBOutlet UILabel *EndLabel;
IBOutlet UILabel *StartLabel;
MBProgressHUD *HUD;
IBOutlet UIDatePicker *datePicker;
IBOutlet UITableViewCell *IntervalCell;
__unsafe_unretained id <updateIntervalDelegate> delegate;
}
@property (nonatomic, strong) UIActionSheet *actionSheet;
@property (nonatomic, strong) UITextField *interval;
@property (nonatomic, retain) NSURL *url;
@property (nonatomic, retain) NSString *StartDate;
@property (nonatomic, retain) NSString *EndDate;
@property(nonatomic, assign)id <updateIntervalDelegate> delegate;
@property (retain, nonatomic) NSString* noId;
-(IBAction)PreviousView:(id)sender;
-(IBAction)updateInterval:(id)sender;
@end
in m.file
@synthesize actionSheet,interval,url,noId,StartDate,EndDate,delegate;
[delegate intervalRefresh:interval.text];
calling the delegate method.
so this is in the implementation class .h file
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "tableInterval.h"
#import "ListMeterCell.h"
#import "PopoverView.h"
#import "MBProgressHUD.h"
@interface ElectricMeterController : UIViewController<UITableViewDelegate,UITableViewDataSource, PopoverViewDelegate,MBProgressHUDDelegate,updateIntervalDelegate> {
PopoverView *pv;
MBProgressHUD *HUD;
}
in .m file
-(void)intervalRefresh:(NSString *)interval{
NSLog(@"delegate fired!");
NSDictionary *copy=[updatedInfo mutableCopy];
[copy setValue:interval forKey:@"interval"];
[temp removeObjectAtIndex:path.row];
[temp insertObject:copy atIndex:path.row];
[self.MeterList reloadData];
}
so the nslog not fired, why? did i miss something here?
Upvotes: 0
Views: 770
Reputation: 5133
Use this pattern when calling delegate:
if (delegate && [delegate respondsToSelector:@selector(intervalRefresh:)])
[delegate intervalRefresh:interval.text];
else NSLog(@"delegate (%@) not responding", delegate);
to ensure delegate property is set and delegate object implements protocol.
Upvotes: 1
Reputation: 2545
Did You set controllerName.delegate = self; ??? I think that must be the only problem you should set the delegate first .
Upvotes: 1