我控制器從UIView類的信息發送給UIViewController的
#import <UIKit/UIKit.h>
#import "ViewBoard.h"
@interface BallsViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *InfoLabel;
@property (weak, nonatomic) IBOutlet UIButton *nextBallButton;
@property (weak, nonatomic) IBOutlet UILabel *PointLabel;
@property (weak, nonatomic) IBOutlet ViewBoard *viewBoard;
- (IBAction)NewGame:(id)sender;
@end
#import "BallsViewController.h"
#import "Field.h"
@interface BallsViewController()
@end
@implementation BallsViewController
@synthesize viewBoard;
- (void)viewDidLoad
{
[super viewDidLoad];
[self.viewBoard Draw:@"Fields"];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)NewGame:(id)sender {
self.viewBoard.canDrawBall = true;
[self.viewBoard Draw:@"Fields"];
}
@end
而且UIView
@interface ViewBoard : UIView
@end
@implementation ViewBoard
-(void)sendScoreToUI{
int score = 10;
}
@end
我怎麼能發送約比分UI信息,並有將其設置爲標籤?我想UIView
發送這個信息給控制器比控制器從UIView
得到它。
您可以通過直接調用某個方法從控制器與您的自定義視圖進行通信,因爲控制器具有該ViewBoard的實例。要創建從視圖到控制器的通信,最好的方法可能是使用協議。該視圖可以有一個代表響應該協議(這將是控制器),並可以從中調用一些功能。這是回答你的問題嗎? –