2013-10-28 15 views
6

Web sunucusuna bağlanmak için özel bir web api kullanan bu eğiticiye (http://bit.ly/NI9kQe) göre bir Uygulama yapıyorum. Gereksinimlerden biri Giriş veya Kayıt düğmesine dokunup duyulmadığını tespit etmektir. Bu, arayüz oluşturucudaki düğme için ayarlanmış bir "etiket" kullanılarak yapılır (yazmaç düğmesi bir 1 etiketine sahiptir). aşağıdaki gibi kod öbek btnLoginRegisterTapped yöntemi içinde oturur'_strong id' türünde nesne 'tag' bulunamıyor

(hata satırda oluşur -> NSString * komutunu = (sender.tag == 1) ' "kayıt": "giriş" @;):

- (IBAction)btnLoginRegisterTapped:(id)sender { 

//form fields validation 
if (fldUserName.text.length < 4 || fldPassword.text.length < 4) { 
    // [UIAlertView error:@"Enter username and password over 4 chars each."]; 

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Opps!!" message:@"Enter username and password over 4 chars each." delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil]; 
    // optional - add more buttons: 
    [alert addButtonWithTitle:@"Yes"]; 
    [alert show]; 
    return; 

} 

//salt the password 
NSString* saltedPassword = [NSString stringWithFormat:@"%@%@", fldPassword.text, kSalt]; 

//prepare the hashed storage 
NSString* hashedPassword = nil; 
unsigned char hashedPasswordData[CC_SHA1_DIGEST_LENGTH]; 

//hash the pass 
NSData *data = [saltedPassword dataUsingEncoding: NSUTF8StringEncoding]; 
if (CC_SHA1([data bytes], [data length], hashedPasswordData)) { 
    hashedPassword = [[NSString alloc] initWithBytes:hashedPasswordData length:sizeof(hashedPasswordData) encoding:NSASCIIStringEncoding]; 
} else { 

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Opps!!" message:@"Password cannot be reset!" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil]; 
    // optional - add more buttons: 
    [alert addButtonWithTitle:@"Yes"]; 
    [alert show]; 
    return; 
} 

//************ THIS IS WHERE THE ERROR OCCURS *****************// 
//check whether it's a login or register 
NSString* command = (sender.tag==1)[email protected]"register":@"login"; 
NSMutableDictionary* params =[NSMutableDictionary dictionaryWithObjectsAndKeys: 
           command, @"command", 
           fldUserName.text, @"username", 
           hashedPassword, @"password", 
           nil]; 

//make the call to the web API 
[[API sharedInstance] commandWithParams:params 
          onCompletion:^(NSDictionary *json) { 
           //handle the response 
           //result returned 
           NSDictionary* res = [[json objectForKey:@"result"] objectAtIndex:0]; 

           if ([json objectForKey:@"error"]==nil && [[res objectForKey:@"IdUser"] intValue]>0) { 
            //success 
            [[API sharedInstance] setUser: res]; 
            [self.presentingViewController dismissViewControllerAnimated:YES completion:nil]; 

            //show message to the user 
            [[[UIAlertView alloc] initWithTitle:@"Logged in" 
                   message:[NSString stringWithFormat:@"Welcome %@",[res objectForKey:@"username"] ] 
                   delegate:nil 
                cancelButtonTitle:@"Close" 
                otherButtonTitles: nil] show]; 

           } else { 
            //error 

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Opps!!" message:@"Server down? Try Again" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil]; 
            // optional - add more buttons: 
            [alert addButtonWithTitle:@"Yes"]; 
            [alert show]; 
            return; 

           } 

          }]; 

}

projeyi (aslında çalışma alanı) hatası alıyorum inşa etmeye çalışın:

I 'id _strong' türündeki nesne üzerinde bulunmayan Property 'etiketi' bir iOS7 için xcode 5.0'ı kullanarak m.

sayesinde

cevap

15

Mülkiyet sözdizimi jenerik id tipi değişkenleri kullanılamaz.

Yani ya [sender tag] veya iyi, yöntem tanımında sender tartışmanın asıl türünü kullanmak yöntem çağrısıyla sender.tag değiştirin:

- (IBAction)btnLoginRegisterTapped:(UIButton *)sender { ... } 

İpucu: "Kontrollü işlemi oluşturmaya -Drive "Xcode, " göndericinin gerçek tipini seçmek için "Type" alanındaki pop-up'ı kullanın. Ardından, doğru bağımsız değişken türü ile eylem yöntemi oluşturulur.

enter image description here

+0

Awesome..thanks çok !! – Cybernetic

+0

@ user1639594: Rica ederim! –

İlgili konular