hi I’m trying load data from my online server to view controller but I m getting few issues in that. Using the nsobject and json I’m trying to load in my view controller. I’m stuck with connecting the nsobject to the labels which i have in my storybord.
this is the nsboject code h file and m file
@interface vote : NSObject
@property (nonatomic,strong) NSString * question;
@property (nonatomic,strong) NSString * choose1;
@property (nonatomic,strong) NSString * choose2;
-(id) initWithquestion: (NSString *) qut andchoose1: (NSString *) ch andchoose2: (NSString *) cho;
this is code which i have used in my viewcontorller m file to get the datas.
#define getDataURL @"http://localhost/poll/view.php"
@implementation pollingpoliticalViewController
@synthesize que,cho1,cho2;
@synthesize json,pollarray;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
//vote *cnnt = [pollarray ];
// Do any additional setup after loading the view.
}
-(void) retrieveData
{
NSURL * url =[NSURL URLWithString:getDataURL];
NSData * data=[NSData dataWithContentsOfURL:url];
json =[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
pollarray = [[NSMutableArray alloc]init];
for (int i=0; i<json.count; i++) {
NSString * dd =[[json objectAtIndex:i]objectForKey:@"ques"];
NSString * plae= [[json objectAtIndex:i]objectForKey:@"choss1"];
NSString * ti =[[json objectAtIndex:i]objectForKey:@"choss2"];
vote *myarray =[[vote alloc]initWithquestion:dd andchoose1:plae andchoose2:ti];
[pollarray addObject:myarray];
}
}
im stuck with the connecting with mutable array to the label which in my view controller so pls somebody suggest weather this is right way to do or what i have to do connect the datas to my view controller..
in tableview we use like we use like this:
fieldpolitical * cunt=[eventarray objectAtIndex:indexPath.row];
detailvc.detail = cunt.title;
detailvc.pla = cunt.place;
detailvc.tim = cunt.time;
detailvc.dat = cunt.date;
// detailvc.stott
i want to do same thing for my controller view
thanks