2013-10-28 8 views
6

की वस्तु पर नहीं मिला है, मैं इस ट्यूटोरियल (http://bit.ly/NI9kQe) के अनुसार एक ऐप बना रहा हूं जो वेब सर्वर से कनेक्ट करने के लिए एक कस्टम वेब एपीआई का उपयोग करता है। आवश्यकताओं में से एक यह पता लगाने के लिए है कि लॉगिन या रजिस्टर बटन टैप किया गया है या नहीं। यह "टैग" का उपयोग करके किया जाता है जिसे इंटरफ़ेस बिल्डर में बटन के लिए सेट किया गया है (रजिस्टर बटन में 1 का टैग है)।संपत्ति 'टैग' प्रकार '_strong id'

कोड का हिस्सा btnLoginRegisterTapped विधि के अंदर बैठता है (त्रुटि लाइन पर होती है -> NSString * command = (sender.tag == 1)? @ "रजिस्टर": @ "लॉगिन";):

- (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; 

           } 

          }]; 

}

जब मैं परियोजना (कार्यक्षेत्र वास्तव में) मैं त्रुटि मिलती है बनाने की कोशिश:

संपत्ति 'टैग' प्रकार की वस्तु पर 'आईडी _strong'

मैं नहीं मिला ए मैं आईओएस 7 के लिए एक्सकोड 5.0 तैनाती का उपयोग कर रहा हूँ।

धन्यवाद,

उत्तर

15

संपत्ति वाक्य रचना सामान्य id प्रकार के चर के साथ नहीं किया जा सकता।

तो या तो विधि कॉल द्वारा sender.tag की जगह [sender tag] या बेहतर, विधि परिभाषा sender तर्क के वास्तविक प्रकार का उपयोग करें:

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

युक्ति: जब "नियंत्रण के साथ कार्रवाई बनाने -ड्राग "एक्सकोड में, प्रेषक के वास्तविक प्रकार का चयन करने के लिए" प्रकार "फ़ील्ड में पॉप-अप का उपयोग करें। फिर क्रिया विधि सही तर्क प्रकार के साथ बनाई गई है।

enter image description here

+0

Awesome..thanks इतना !! – Cybernetic

+0

@ उपयोगकर्ता 1639594: आपका स्वागत है! –

संबंधित मुद्दे