有两个IBOutlet,即使它们包含在视图控制器文件中,也不会出现在文件所有者中以进行连接。为什么呢?
以下是接口和实现文件的代码。使用Xcode 4.2。
CoinTossViewController.h
#import <UIKit/UIKit.h>
@interface CoinTossViewController : UIViewController {
UILabel *status;
UILabel *result;
}
@property (nonatomic, retain)UILabel *status;
@property (nonatomic, retain)UILabel *result;
- (IBAction)callHeads;
- (IBAction)callTails;
@end
ToinCossViewController.m
#import "CoinTossViewController.h"
#import <QuartzCore/QuartzCore.h>
@implementation CoinTossViewController
@synthesize status, result;
- (void)simulateCoinToss:(BOOL)userCalledHeads {
BOOL coinLandedOnHeads = (arc4random() % 2) == 0;
result.text = coinLandedOnHeads ? @"Heads" : @"Tails";
if (coinLandedOnHeads == userCalledHeads)
status.text = @"Correct!";
else
status.text = @"Wrong!";
CABasicAnimation *rotation = [CABasicAnimation
animationWithKeyPath:@"transform.rotation"];
rotation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
rotation.fromValue = [NSNumber numberWithFloat:0.0f];
rotation.toValue = [NSNumber numberWithFloat:720 * M_PI / 180.0f];
rotation.duration = 2.0f;
[status.layer addAnimation:rotation forKey:@"rotate"];
CABasicAnimation *fade = [CABasicAnimation animationWithKeyPath:@"opacity"];
fade.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
fade.fromValue = [NSNumber numberWithFloat:0.0f];
fade.toValue = [NSNumber numberWithFloat:1.0f];
fade.duration = 3.5f;
[status.layer addAnimation:fade forKey:@"fade"];
}
- (IBAction)callHeads
{
[self simulateCoinToss:YES];
}
- (IBAction)callTails
{
[self simulateCoinToss:NO];
}
- (void) viewDidUnload
{
self.status = nil;
self.result = nil;
}
- (void) dealloc
{
[status release];
[result release];
[super dealloc];
}
@end
答案 0 :(得分:5)
您没有在那里定义任何IBOutlets。您想要状态和结果是出口吗?如果是这样,请执行以下操作:
@property (nonatomic, retain) IBOutlet UILabel *status;
@property (nonatomic, retain) IBOutlet UILabel *result;
答案 1 :(得分:1)
尝试将标题更改为:
#import <UIKit/UIKit.h>
@interface CoinTossViewController : UIViewController {
UILabel *status;
UILabel *result;
}
@property (nonatomic, retain)IBOutlet UILabel *status;
@property (nonatomic, retain)IBOutlet UILabel *result;
- (IBAction)callHeads;
- (IBAction)callTails;
@end