2日間試した後、私は今頭がおかしくなっています...主な問題は単純です..私はuiviewにボタンを持っていて、uiviewcontrollerでメソッドを呼び出したいです...これがコードです
Uiview 呼び出し headerView.h
@class HeaderView;
@protocol headerViewDelegate
- (void)tes:(HeaderView *)tes ratingDidChange:(float)rating;
@end
@interface HeaderView : UIView {
UIButton *test;
}
@property (nonatomic,strong) UIButton *test;
@property (assign) id <headerViewDelegate> delegate;
@end
および Headerview.M
#import "HeaderView.h"
#import <QuartzCore/QuartzCore.h>
@implementation HeaderView
@synthesize test;
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame]; // not needed - thanks ddickison
if (self) {
test=[UIButton buttonWithType:UIButtonTypeRoundedRect];
test.frame=CGRectMake(30, 10, 100,40);
[test setTitle:@"Kampret" forState:UIControlStateNormal];
[test addTarget:self action:@selector(testdata:) forControlEvents:UIControlEventTouchUpInside];
}
[self addSubview:test];
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder {
if ((self = [super initWithCoder:aDecoder])) {
}
return self;
}
- (void)dealloc {
[super dealloc];
}
-(void)layoutSubviews{
self.backgroundColor=[UIColor whiteColor];
[self release]; // release object before reassignment to avoid leak - thanks ddickison
//self = [nib objectAtIndex:0];
self.layer.shadowColor = [[UIColor blackColor] CGColor];
self.layer.shadowOffset = CGSizeMake(1.0, 1.0);
self.layer.shadowOpacity = 0.40;
}
-(void)testdata:(id)sender{
[self.delegate tes:self ratingDidChange:1.1f];
}
@end
viewcontroller.h
#import <UIKit/UIKit.h>
#import "HeaderView.h"
@interface ReusableTableHeadersViewController : UITableViewController <headerViewDelegate> {
HeaderView *header;
}
@property(nonatomic,strong) HeaderView *header;
@end
viewcontroller.m
#import "viewcontroller.h"
@implementation ReusableTableHeadersViewController
@synthesize header;
@synthesize tblData, data;
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
header = [[HeaderView alloc] initWithFrame:CGRectMake(0, 0, 320, 120)];
[self.view addSubview:header];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
}
- (void)dealloc {
[super dealloc];
}
-(void)tes:(HeaderView *)tes ratingDidChange:(float)rating{
NSLog(@"passing data==========%f",rating);
}
@end
評価を記録したい : NSLog(@"passing data==========%f",rating);
メソッドから:
-(void)testdata:(id)sender{
[self.delegate tes:self ratingDidChange:1.1f];
}
しかし、何も表示されません...なぜですか?私はinitwithframeを使用するので?
私を責めないでください...私はここではまったく初心者です:)