我的应用程序的基本前提是,当它加载时它隐藏按钮“findMe”然后当选择按钮“go”时它会显示按钮并将其设置为特定坐标(一旦我解决了这个问题,我就是要实现随机坐标)。问题是我的按钮在应用程序加载时没有隐藏,“go”按钮不会改变坐标。我在界面构建器中创建了按钮。我不确定为什么这不起作用,因为这似乎是一件容易的事。非常感谢我在哪里出错了。感谢。
.h文件
#import <UIKit/UIKit.h>
@interface Senior_DesignViewController : UIViewController
<UIAlertViewDelegate> {
IBOutlet UIButton *findMe;
IBOutlet UIButton *go;
IBOutlet UILabel *success;
}
@property (retain, nonatomic) UIButton *findMe;
@property (retain, nonatomic) UILabel *success;
@property (retain, nonatomic) UIButton *go;
-(IBAction)foundMe:(id)sender;
-(IBAction)go:(id)sender;
@end
.m文件
#import "Senior_DesignViewController.h"
@implementation Senior_DesignViewController
@synthesize findMe;
@synthesize success;
@synthesize go;
-(IBAction)foundMe:(id)sender {
UIAlertView *alertDialog;
alertDialog = [[UIAlertView alloc]
initWithTitle:@"Congratulations"
message:@"You have found the box"
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alertDialog show];
[alertDialog release];
}
-(IBAction)go:(id)sender {
findMe.frame = CGRectMake(100, 100, 50, 50);
findMe.hidden = NO;
}
- (void)viewDidLoad {
findMe.hidden = YES;
UIAlertView *alertDialog;
alertDialog = [[UIAlertView alloc]
initWithTitle:@"Welcome to our SNR DSN App"
message:@"Please Calibrate NOW!"
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alertDialog show];
[alertDialog release];
[super viewDidLoad];
}
答案 0 :(得分:2)
确保在Interface Builder中连接出口和操作。这些按钮应作为Referencing Outlets附加到文件所有者,并且操作应该连接到Touch Up Inside事件。