2016-05-27 14 views
0

Object returns nil Beschreibung nach Alloc und init..kann irgendjemand mir sagen, ich muss die Daten anzeigen, die vom Server kommt ... wenn ich auf Bearbeiten klicke, geht es zu shoow Raumklasse in dieser Klasse .. innerhalb Textfelder hav die Informationen .can einem helfen miriOS: Object gibt keine Beschreibung nach Alloc und Init

@interface HeadOfficeDetails : NSObject 

@property(nonatomic,strong) NSMutableArray *ofcContact; 

@property(nonatomic,strong) OfficeDocument *ofcDocument; 
@property(nonatomic,strong) OfficePrice *ofcPrice; 
@property(nonatomic,strong) CityClass *city; 
@property(nonatomic,strong) StateClass *state; 
@property(nonatomic,strong) DistrictClass *district; 

@property(nonatomic,strong)NSString *shrtname; 
@property(nonatomic,strong)NSString *shwrmname; 
@property(nonatomic,strong)NSString *shop; 
@property(nonatomic,strong)NSString *door; 
@property(nonatomic,strong)NSString *buildng; 
@property(nonatomic,strong)NSString *flr; 
@property(nonatomic,strong)NSString *tele; 
@property(nonatomic,strong)NSString *pin; 
@property(nonatomic,strong)NSString *main; 
@property(nonatomic,strong)NSString *dist; 
@property(nonatomic,strong)NSString *designan; 
@property(nonatomic,strong)NSString *depart; 
@property(nonatomic,strong)NSString *emai; 
@property(nonatomic,strong)NSString *mobile; 
@property(nonatomic,strong)NSString *strt; 
@property(nonatomic,strong)NSString *area; 


@property(nonatomic,strong) NSString *jwleryname; 
@property(nonatomic,strong) NSString *officeid; 


-(void)setAttributes:(NSDictionary *)attributes; 




/////////////////////////////////////////////// 
showroom class 



headdetails=[[HeadOfficeDetails alloc]init]; 


self.txtshowroom.text=headdetails.jwleryname; 
NSLog(@"%@ :",self.txtshowroom.text); 


NSNumber *officeid=headdetails.officeid; 
NSLog([NSString stringWithFormat:@"%@",officeid]); 

[self.txtshortname setText:headdetails.jwleryname]; 
[self.txtshowroom setText:headdetails.shwrmname]; 
[self.txtstreet setText:headdetails.strt]; 
[self.txtarea setText:headdetails.area]; 
[self.txtmain setText:headdetails.main]; 
[self.txtbuilding setText:headdetails.buildng]; 
[self.txtname setText:self.cntctcls.contactname]; 
[self.txtdesign setText:self.cntctcls.desig]; 
[self.txtdepartmnt setText:self.cntctcls.depart]; 
[self.txtmbl setText:self.cntctcls.mobile]; 
[self.txtemail setText:self.cntctcls.email]; 
[self.txtfloor setText:headdetails.flr]; 
[self.txttel setText:headdetails.tele]; 
[self.txtpincode setText:headdetails.pin]; 
[self.txtshop setText:headdetails.shop]; 

Antwort

0
anzuzeigen

Hier sind i Beispielcode stellen für die Show NSObject Klasse Daten, die vom Server holen während Daten speichern und zeigen auf eine andere Klasse, indem Sie ihre Instanz verwenden.

Es folgt eine NSObject Klasse erstellen für FBLogin userDetauls Speicherung:

#import <Foundation/Foundation.h> 

@interface FBUser : NSObject 

@property (nonatomic,strong) NSString *FBUserId; 
@property (nonatomic,strong) NSString *FBUserName; 
@property (nonatomic,strong) NSString *FBUserFirstName; 
@property (nonatomic,strong) NSString *FBUserLasttName; 
@property (nonatomic,strong) NSString *FBUserEmail; 
@property (nonatomic,strong) NSString *FBUserBio; 
@property (nonatomic,strong) NSString *FBUserLocation; 

+(instancetype)SharedFBUser; 
-(void)ClearFBuser; 
+(NSString*)CheckEmtryElseAlert:(NSString*)strValue; 

@end 

Es folgt ein Implementierungsklasse hier wir SharedFBUser erstellen, die FBUser Objekt einmal allcate wenn die Null so gefunden, wenn keine Notwendigkeit, Code zu tun allocinit während zeigen Zeit

#import "FBUser.h" 


static FBUser* fbObject; 

@implementation FBUser 

+(instancetype)SharedFBUser 
{ 
    if(fbObject == nil) 
    { 
     fbObject =[[FBUser alloc]init]; 
    } 

    return fbObject; 
} 
-(void)ClearFBuser 
{ 

    fbObject = nil; 
    self.FBUserId = nil; 
    self.FBUserName = nil; 
    self.FBUserFirstName =nil; 
    self.FBUserLasttName = nil; 
    self.FBUserEmail = nil; 
    self.FBUserBio = nil; 
    self.FBUserLocation = nil; 

} 

nun folgenden Code für wie FBUser Klasse verwenden für die Daten .H Klasse sparen:

#import <UIKit/UIKit.h> 
#import "FBUser.h" 
@interface LoginViewController : UIViewController 
@property(nonatomic,strong)FBUser *fbObject; 
@end 

Und Sie können Daten in FBCallback sparen:

[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name, link, first_name, last_name, picture.type(large), email, birthday, bio ,location ,friends ,hometown , friendlists"}] 
    startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { 
     if (!error) 
     { 
      NSLog(@"resultis:%@",result); 
      [FBUser SharedFBUser].FBUserId =[result valueForKey:@"id"]; 
      [FBUser SharedFBUser].FBUserEmail =[result valueForKey:@"email"]; 
       [FBUser SharedFBUser].FBUserName =[result valueForKey:@"name"]; 
      [FBUser SharedFBUser].FBUserFirstName =[result valueForKey:@"first_name"]; 
      [FBUser SharedFBUser].FBUserLasttName =[result valueForKey:@"last_name"]; 
     } 
     else 
     { 
      NSLog(@"Error %@",error); 
     } 
    }]; 

und die Daten folgenden Code für die Show, die

#import "FBUser.h" 
    self.lblEmail.text = [FBUser SharedFBUser].FBUserEmail; 
    self.lblusename.text = [FBUser SharedFBUser].FBUserName; 
    self.lblfirstname.text = [FBUser SharedFBUser].FBUserFirstName; 
    self.lbllastname.text = [FBUser SharedFBUser].FBUserLasttName; 

Hoffnung, dass diese vollständig Beschreibung über die Verwendung helfen in FBuser Klasse gespeichert haben und erstellen. Das ist mein Arbeitscode.

0

Nicht sicher, was machst du, möglicherweise brauchen Sie etwas wie Parse-Wörterbuch, um zuerst zu objektieren.

headdetails=[[HeadOfficeDetails alloc]init];

Neues Objekt erstellt, so dass alle Eigenschaften wird gleich Null.

müssen Sie Wert zuweisen für sie wie

headdetails=[[HeadOfficeDetails alloc]initWithDictionary:attributes]; 

Sie können Ihre selbst analysieren oder eine dritte Bibliothek suchen, wie: JSonModel

+0

ich möchte die Daten in Textfelder zeigen, wann immer der Benutzer klickt auf Edit-Taste und sobald ich jedes Ding im Textfeld aktualisieren es wird –

+0

Ich habe nsobject Klasse dort habe ich die Schlüsselwerte –

+0

Wenn Sie Daten vom Server anfordern, erhalten Sie JSON Return zurück, müssen Sie zuerst analysieren es auf Ihre benutzerdefinierte Objekt und danach können Sie es Ihrer Benutzeroberfläche zuordnen. Ich denke, du bist neu in der iOS-Entwicklung, lies zuerst einige Bücher für Anfänger. RayWenderlic hatte viele gute Tutorials, Sie können dieses https://www.raywenderlich.com/55384/ios-7-best-practices-part-1 lesen, um Ihr Problemgesicht zu verstehen. – Nick

Verwandte Themen