0

嗨,我尝试创建一个委托以将数据从 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;
}

在 .m 文件中

-(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没有被解雇,为什么?我在这里错过了什么吗?

4

2 回答 2

1

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

于 2012-10-29T08:41:03.483 回答
1

调用委托时使用此模式:

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

确保设置了委托属性并且委托对象实现了协议。

于 2012-10-29T08:46:25.073 回答