하위 클래스 UITableViewController 및 내부 테이블에 사용자 지정 셀이 있습니다. 그리고이 사용자 정의 셀은 UIView 내부를 서브 클래 싱했습니다. 따라서이 UIView는 자체 클래스로 작성됩니다. 내 코드에서 UITableViewController 클래스의 이름은 MainViewController.h/.m이고 UIView의 클래스 이름은 ContentView.h/.m입니다. 따라서 ContentView에서 이미지와 tapGestureRecognizer를 추가했습니다. 이미지가 도청 될 때까지 날짜 (이 경우 숫자)가 MainViewController로 전송됩니다. 첫 번째 문제는 위임 메서드가 호출되지 않는다는 것입니다. 그리고 그것을 notificationCenter로 호출하면 0.00000로 기록됩니다. 셀 안의 뷰에서 ViewController로 데이터를 전달할 수 있습니까? 숫자 또는 데이터를 서브 클래 싱 된 UIView에서 UIViewController로 전달하는 방법?
이
내 코드입니다 :ContentView.h :
@class ContentView;
@protocol ContentViewDelegate
- (void)passDigit:(float)someDigit;
@end
#import <UIKit/UIKit.h>
#import "MainViewController.h"
@interface ContentView : UIView
{
id <ContentViewDelegate> delegate;
float someDigit;
}
@property float someDigit;
@property (assign) id <ContentViewDelegate> delegate;
@end
ContentView.m
#import "ContentView.h"
@implementation ContentView
@synthesize someDigit;
@synthesize delegate;
- (void)handleContentTouch:(UIGestureRecognizer *)gesture
{
someDigit = 134;
[self.delegate passDigit:someDigit];
}
- (void)setupView
{
CGRect frame = self.frame;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleContentTouch:)];
UIImageView *fifthBackground = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,100,100)];
[self addSubview:fifthBackground];
[fifthBackground setUserInteractionEnabled:YES];
[fifthBackground addGestureRecognizer:tap];
}
MainViewController.h
#import <UIKit/UIKit.h>
#import "ContentView.h"
@interface MainViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource, UIScrollViewDelegate, ContentViewDelegate>
@end
MainViewContorller.m
#import "MainViewController.h"
@implementation MainViewController
- (void)viewDidLoad
{
[super viewDidLoad];
ContentView *contentView = [[ContentView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
contentView.delegate = self;
}
- (void) passDigit:(float)someDigit
{
NSLog(@"%f",someDigit);
}
왜 마지막 질문을 업데이트하지 않으셨습니까? – rmaddy
내가 바꿨 기 때문에. 여기서는 알림 센터를 사용하지 않습니다. –
정말로 변경하지 않았습니다. 당신은 방금 일부 텍스트를 제거했습니다 ... – pasawaya