我知道這種問題在這裏討論過幾次,但我已經搜索並嘗試沒有成功。我正嘗試在常規菜單的頂部創建一個簡單的登錄視圖。此登錄頁面包含2個文本框(用戶名爲&密碼)和1個按鈕(登錄)。我的問題是,雖然我點擊登錄按鈕時,一切都顯示完美,沒有迴應。以編程方式創建的按鈕不響應用戶的點擊
* 登錄視圖使用moveTo方法從開始到結束點動畫。評論該部分,但仍然沒有迴應。
的main.m
- (void)viewDidLoad
{
prefs = [NSUserDefaults standardUserDefaults];
if (![prefs objectForKey:@"userName"]) {
LoginScreen *login = [[LoginScreen alloc] initWithFrame:CGRectMake(35, 400, 250, 350)];
[self.view addSubview:login];
[login moveTo:CGPointMake(35.0, 65.0) duration:0.6 option:UIViewAnimationOptionCurveEaseOut];
}
[super viewDidLoad];
}
LoginScreen.m在屏幕上
@synthesize login;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.layer.masksToBounds = YES;
self.userInteractionEnabled = YES;
[self addButton:login withTitle:@"Login" andSize:CGRectMake(85, 200, 90, 35)];
[login addTarget:self action:@selector(attemptLogin)
forControlEvents:UIControlEventTouchUpInside];
}
return self;
}
- (void) addButton: (UIButton*) button withTitle: (NSString*) title andSize: (CGRect) size{
button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = size;
[button setTitle:title forState:UIControlStateNormal];
button.userInteractionEnabled = YES;
[self addSubview:button];
}
- (void)attemptLogin{
NSString *user = usernameTxt.text;
NSString *pass = passwordTxt.text;
NSString *url = [[NSString alloc] initWithFormat:@"http://domain.com/login.php?username=%@&password=%@", user, pass];
NSLog(@"%@", url);
}
沒有打印。
在此先感謝
關鍵字:C通過值傳遞函數參數,而不是通過引用。 – 2013-01-24 17:49:08