简体   繁体   English

iOS:对象在alloc和init之后返回nil描述

[英]iOS: Object returns nil description after alloc and init

Object returns nil description after alloc and init..can any one tell me i have to display the data which comes from server...when i clicks on edit button it goes to shoow room class in that class.. inside textfields hav to display the information .can any one help me 对象在alloc和init之后返回nil描述。任何人都可以告诉我我必须显示来自服务器的数据...当我单击“ edit”按钮时,它将进入该类中的小房间类。在文本字段中必须显示该信息。有谁能帮助我

@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];

Here are i put example code for show NSObject class data that save during data fetch from server and show on another class by using its instance. 这是我的示例代码,用于显示NSObject类数据,这些数据在从服务器获取数据期间保存并通过使用其实例在另一个类上显示。

Following is create a NSObject class for storing FBLogin userDetauls: 以下是创建用于存储FBLogin userDetauls的NSObject类:

#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

Following is an Implementation class here we create SharedFBUser that allcate FBUser object once if that found nil so when no need to do code alloc init during show time 下面是一个实现类在这里,我们创建SharedFBUser是allcate FBUser如果发现零,所以当不需要做代码对象一次alloc init期间放映时间

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

}

Now following code for how to use FBUser class for save data .H class: 现在下面的代码说明如何使用FBUser类保存数据.H类:

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

And you can save data in FBCallback: 您可以将数据保存在FBCallback中:

[[[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);
         }
     }];

And following code for show the data that have stored in FBuser class 以下代码显示了存储在FBuser类中的数据

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

Hope that help this fully description about use and create. 希望对本文的使用和创建有所帮助。 this is my working code. 这是我的工作代码。

Not sure what are you doing, may you need something like parse dictionary to object first. 不确定您在做什么,可能需要像parse dictionary这样的对象才能首先成为对象。

headdetails=[[HeadOfficeDetails alloc]init];

New Object created so all properties will nil. 创建了新对象,因此所有属性都将为零。

you need assign value for it like 您需要为其分配值,例如

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

You can parse it your self or looking some 3rd library like: JSonModel 您可以自己解析它,也可以查看一些第3个库,例如: JSonModel

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM