代表不解雇ios

时间:2012-10-29 08:09:28

标签: ios delegates

嗨我试图创建一个委托来将数据从tableInterval反向传递给ElectricMeter uiViewController 但是代表不会解雇。 这是我的代码 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

在m.file

@synthesize actionSheet,interval,url,noId,StartDate,EndDate,delegate;
[delegate intervalRefresh:interval.text];

调用委托方法。

所以这是在实现类.h文件

#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;
}
<。>文件中的

-(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];

}

所以nslog没有解雇,为什么?我在这里想念一下吗?

2 个答案:

答案 0 :(得分:1)

你设置了controllerName.delegate = self; ??? 我认为这必须是你应该首先设置委托的唯一问题。

答案 1 :(得分:1)

调用委托时使用此模式:

if (delegate && [delegate respondsToSelector:@selector(intervalRefresh:)])
    [delegate intervalRefresh:interval.text];
else NSLog(@"delegate (%@) not responding", delegate);

确保设置委托属性,委托对象实现协议。