I am developing a app that will load remote data in a UITableView but when I run it, it shows nothing. Please view and help me to debug it. Thanks
Json outPut
{
"emp_info" = (
(
1,
firstname_one,
lastname_one,
"abcd#xyz",
"500 B3 abc Town"
),
(
2,
firstname_two,
lastname_two,
"abcd#xyz",
"500 B3 abc Town"
),
(
18,
firstname_three,
lastname_three,
"abcd#xyz",
"500 B3 abc Town"
)
);
}
And .m file
- (void)viewDidLoad
{
[super viewDidLoad];
statuses=[[NSMutableArray alloc]init];
NSURL *myURL = [NSURL URLWithString:#"http://abcd.com/My_php/result.php"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:myURL cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSLog(#"Finished with status code: %i", [(NSHTTPURLResponse *)response statusCode]);
id jsonObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
NSLog(#"jsonObject=%#",jsonObject);
statuses=[jsonObject mutableCopy];
[self.theTableView reloadData];
}];
NSLog(#"myURL=%#",myURL);
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(#"%d",[statuses count]);
return [statuses count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ;
}
id obj = [statuses objectAtIndex:indexPath.row];
cell.textLabel.text =[obj valueForKey:#"Title"];
return cell;
}
And when I compile it. it shows nothing in the table infect doesn't even show the table itself.
You should get NSArray contains NSArrays from NSDictionary from JSON:
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
{
...
// This Array contains arrays
statuses=[jsonObject[#"emp_info"] mutableCopy];
[self.theTableView reloadData];
}];
In cellForRowAtIndexPath, get value from this NSArray:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
...
// this is an NSArray, not an NSDictionary:
NSArray *obj = [statuses objectAtIndex:indexPath.row];
cell.textLabel.text = obj[1]; // just my example
}
Your data is a dictionary containing an array.
If you want just the array, get the array from the value object returned by the json parser:
statuses=[[jsonObject valueForKey:#"emp_info"] mutableCopy];
Related
I want to create a message conversation screen.I have two arrays, first is web_array and the second is local_array. First, I have one UITableViewCell in one UILabel, and one UITextField, and one UIButton. In the textfield, write any text and it will print on UITableViewCell label. TextField text is stored in a one array (local_array). (application run time local_array is empty).
And second array (web_array), web_array is stored in a web service get data, I want to web_array count on UITableViewCell label after local_array count in same label.
web_array data counting is over after just down local_array data counting start.
My english is very bad and i can't explain proper. seriously i'm so tired please help me and guide.
ViewController
#import "Chat_ViewController.h"
#import "chatview_Cell.h"
#interface Chat_ViewController () <UITableViewDataSource,UITableViewDelegate>
{
NSArray*web_array;
NSMutableArray*Local_array;
}
#end
#implementation Chat_ViewController
- (void)viewDidLoad {
[super viewDidLoad];
Local_array=[[NSMutableArray alloc]init];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:#"MYURL"]];
//create the Method "GET" or "POST"
[request setHTTPMethod:#"POST"];
//Pass The String to server(YOU SHOULD GIVE YOUR PARAMETERS INSTEAD OF MY PARAMETERS)
NSString *userUpdate =[NSString stringWithFormat:#"senderid=%#&recid=%#&",_chat_myuid.text,_chat_uid.text, nil];
//Check The Value what we passed
NSLog(#"the data Details is =%#", userUpdate);
//Convert the String to Data
NSData *data1 = [userUpdate dataUsingEncoding:NSUTF8StringEncoding];
//Apply the data to the body
[request setHTTPBody:data1];
//Create the response and Error
NSError *err;
NSURLResponse *response;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&err];
NSString *resSrt = [[NSString alloc]initWithData:responseData encoding:NSASCIIStringEncoding];
//This is for Response
NSLog(#"got response==%#", resSrt);
NSArray *results = [json objectForKey:#"status"];
web_array = [results valueForKey:#"message"];
NSLog(#"your message %#",web_array);
//This is for Response
NSLog(#"got response==%#", resSrt);
if(resSrt)
{
NSLog(#"got response");
}
else
{
NSLog(#"faield to connect");
}
}
- (IBAction)send:(id)sender
{
NSString *textNameToAdd = self.mymsg.text; //mymsg is UITextField outlet
[Local_array addObject:textNameToAdd];
[self.table_view reloadData];
}
//TABLEVIEWCELL Code
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if ([Local_array count] > 0 && web_array.count>0)
{
return [Local_array count];
}
else
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
chatview_Cell *cell = [tableView dequeueReusableCellWithIdentifier:#"ht"];
if (cell==nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"Cell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
if (Local_array.count > 0 && web_array.count>0)
{
cell.other_msg.text=[NSString stringWithFormat:#"%#",[Local_array objectAtIndex:indexPath.row]];
}
cell.other_msg.text=[NSString stringWithFormat:#"%#",[web_array objectAtIndex:indexPath.row]];
return cell;
}
How to array data reload in UITableView? I use a web services and fetch data stored in a array. I got a data and print on consol but same array can't reload in TableView.
Please help me how to show data on table view i trying to many times but can't show data.
JSON
{
"status": {
"event": [
{
"event_id": "28",
"event_name": "Event name",
"event_title": "svsav",
"img": "http:\/\/edutimeapp.com\/toshow\/chamber-of-commerc\/uploads\/1461402793-Vtcg8pRB.jpg",
"event_date": "2016-04-05",
"event_time": "12:00",
"event_detail": "svsa"
},
viewcontroller
#import "ViewController.h"
#import "celltable.h"
#interface ViewController ()
{
NSArray*name;
}
#end
- (void)viewDidLoad {
[super viewDidLoad];
[self.tableview setAllowsMultipleSelection:YES];
NSURLRequest *req=[[NSURLRequest alloc]initWithURL:[NSURL URLWithString:#"http://edutimeapp.com/toshow/chamber-of-commerc/ws/fetch_event.php"]];
response =[[NSMutableData alloc]init];
[NSURLConnection connectionWithRequest:req delegate:self];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[response appendData:data];
NSLog(#"error receving data %#",response);
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSError *error;
NSLog(#"Error in receiving data %#",error);
NSMutableDictionary *json = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
NSLog(#"response data %#",son);
NSError *jsonParsingError = nil;
NSDictionary *retrievedJTransD = [NSJSONSerialization JSONObjectWithData:response options:0 error:&jsonParsingError];
NSArray* retrievedJTrans = retrievedJTransD[#"status"][#"event"];
name = [retrievedJTrans valueForKey:#"event_name"];
NSLog(#"success %#", name);
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [name count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(#"tableview cell");
celltable *cell = [tableView dequeueReusableCellWithIdentifier:#"ht"];
if (cell==nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"Cell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.date.text=[NSString stringWithFormat:#"%#",[name objectAtIndex:indexPath.row]];
return cell;
}
Your mistake is cannot reload the tableview, next you did not correctly set the array values, Use this below code,
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSError *error;
NSLog(#"Error in receiving data %#",error);
NSMutableDictionary *json = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
NSLog(#"response data %#",son);
NSError *jsonParsingError = nil;
NSDictionary *retrievedJTransD = [NSJSONSerialization JSONObjectWithData:response options:0 error:&jsonParsingError];
NSArray* retrievedJTrans = retrievedJTransD[#"status"][#"event"];
//you are wrong in name array change it.
name = retrievedJTrans;
NSLog(#"success %#", name);
[self.tableview reloadData];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [name count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(#"tableview cell");
celltable *cell = [tableView dequeueReusableCellWithIdentifier:#"ht"];
if (cell==nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"Cell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.date.text=[NSString stringWithFormat:#"%#",[[name objectAtIndex:indexPath.row] valueForKey:#"event_name"]];
return cell;
}
hope its helpful
After You get response from WS
dispatch_async(dispatch_get_main_queue(), ^{
[self.yourTableview reloadData];
});
Always remember that when you need reload tableview and you are using WS Call or any other block operations reload it in main thread
I have a NSString as result of a URLRequest.
NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
if(responseString && responseString.length) {
// NSLog(#"DATOS RECIBIDOS EN HISTORIAL=%#", responseString);
NSError *jsonError;
NSData *objectData = [responseString dataUsingEncoding:NSUTF8StringEncoding];
json = [NSJSONSerialization JSONObjectWithData:objectData
options:NSJSONReadingMutableContainers
error:&jsonError];
NSArray *messageArray = [json objectForKey:#"objects"];
// Parse and loop through the JSON
for (json in messageArray) {
NSString * code = [json objectForKey:#"code"];
NSDictionary *level2Dict = [json objectForKey:#"client"];
NSString *email = [level2Dict objectForKey:#"email"];
//NSString * nombre = someObject;
NSLog(#"CODIGO DE CLIENTE=%#",code);
NSLog(#"EMAIL DEL CLIENTE=%#",email);
}
Then I convert the string to a NSData that I deserialise into a json string.
Later I am able to iterate the array of dictionaries to get the value from some of the json objects.
But for hours I am trying to pass all this information to a table view, but I am not able. From the above code what should I do to get the needed information to be shown on a table view?
Thank you.
EDITED QUESTION:
#interface HistorialReservasViewController () {
NSArray *messageArray;
}
#end
- (void)viewDidLoad {
[super viewDidLoad];
UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle:#"Home" style:UIBarButtonItemStyleBordered target:self action:#selector(home:)];
self.navigationItem.leftBarButtonItem=newBackButton;
self.title = #"Corona";
//REQUEST DEL HISTORIAL
messageArray = [[NSArray alloc] init]; // just so array is not nil
//1. client , lo tomamos de la variable del sistema
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];//se crea una instancia de la variable del sistema
//LOS PARAMETROS NECESARIOS SON client y date
//buscamos client
NSString *idcliente = [defaults objectForKey:#"idUsuario"];
NSLog(#"ID CLIENTE=&%#",idcliente);
NSString *cliente = idcliente;
NSDateFormatter *formatter;
NSString *dateString;
formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:#"yyyy-MM-dd"];
dateString = [formatter stringFromDate:[NSDate date]];
NSLog(#"FECHA=%#", dateString);
NSString *fecha = dateString;
NSLog(#"CLIENTE=%#",cliente);
NSLog(#"FECHA=%#",fecha);
//request
NSURL *apiURL = [NSURL URLWithString:
[NSString stringWithFormat:#"http://hidden here/?client=%#&date=%#", cliente,fecha]];
NSURLRequest *request = [NSURLRequest requestWithURL:apiURL]; // this is using GET, for POST examples see the other answers here on this page
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
if(data.length) {
NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
if(responseString && responseString.length) {
// NSLog(#"DATOS RECIBIDOS EN HISTORIAL=%#", responseString);
NSError *jsonError;
NSData *objectData = [responseString dataUsingEncoding:NSUTF8StringEncoding];
json = [NSJSONSerialization JSONObjectWithData:objectData
options:NSJSONReadingMutableContainers
error:&jsonError];
messageArray = [json objectForKey:#"objects"];
// Parse and loop through the JSON
for (json in messageArray) {
NSString * code = [json objectForKey:#"code"];
NSDictionary *level2Dict = [json objectForKey:#"client"];
NSString *email = [level2Dict objectForKey:#"email"];
// id someObject = [level2Dict objectForKey:#"name"];
// NSLog(#"NOMBRE===%#",someObject);
//NSString * nombre = someObject;
NSLog(#"CODIGO DE CLIENTE=%#",code);
NSLog(#"EMAIL DEL CLIENTE=%#",email);
}
}
}
}];
NSLog(#"NUMERO ED ITEMS=%lu", (unsigned long)messageArray.count);
}
//METODOS PARA LA CONEXION
-(void)home:(UIBarButtonItem *)sender {
[self performSegueWithIdentifier:#"mapa_segue" sender:self];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [messageArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell" forIndexPath:indexPath];
cell.textLabel.text = [[messageArray objectAtIndex:indexPath.row] objectForKey:#"code"];
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return NO;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
}
You are not passing your data to your tableview at all. You need to create global array and initializes this array in viewDidLoad, populate it like you do and use it in your tableview functions.
NSArray *messageArray;
in view did load change this line
-(void)viewDidLoad{
messageArray = [[NSArray alloc] init]; // just so array is not nil
messageArray = [json objectForKey:#"objects"];
}
And use this array to populate your tableview
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [messageArray count]; //this will ensure you will have as many cells in your table view as there are values in your array
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell" forIndexPath:indexPath];
//here you use your array and fill cell with your data
// you need to have a UILabel in cell which is called "codeLabel" but feel free to name it whatever you want
cell.codeLabel.text = [[messageArray objectAtIndex:indexPath.row] objectForKey:#"code"]; //to fill your codelabel with code value from array
cell.otherLabel.text = [[messageArray objectAtIndex:indexPath.row] objectForKey:#"other"]; //just another value
return cell;
}
EDIT
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
if(data.length) {
NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
if(responseString && responseString.length) {
// NSLog(#"DATOS RECIBIDOS EN HISTORIAL=%#", responseString);
NSError *jsonError;
NSData *objectData = [responseString dataUsingEncoding:NSUTF8StringEncoding];
json = [NSJSONSerialization JSONObjectWithData:objectData
options:NSJSONReadingMutableContainers
error:&jsonError];
messageArray = [json objectForKey:#"objects"];
NSLog(#"NUMERO ED ITEMS=%lu", (unsigned long)messageArray.count);
//all UI updates must be called from main thread, thats why reload data must be wrapped in this call for more info google "ios GCD"
dispatch_async(dispatch_get_main_queue){
[tableView reloadData];
}
// Parse and loop through the JSON
for (json in messageArray) {
NSString * code = [json objectForKey:#"code"];
NSDictionary *level2Dict = [json objectForKey:#"client"];
NSString *email = [level2Dict objectForKey:#"email"];
// id someObject = [level2Dict objectForKey:#"name"];
// NSLog(#"NOMBRE===%#",someObject);
//NSString * nombre = someObject;
NSLog(#"CODIGO DE CLIENTE=%#",code);
NSLog(#"EMAIL DEL CLIENTE=%#",email);
}
}
}
}];
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How to parse the following link:-
http://www.cbapcertprep.com/service/index.php?/Download_vehicletrack/DownloadTrackData/35170
how to show longitude and latitude data in table?
assume that this is your .m file
#interface searchResultsViewController ()
{
NSMutableArray *getlot, *getlong;
}
#end
in your view did load
-(void)viewDidLoad
{
getlong =[[NSMutableArray alloc]init];
getlot =[[NSMutableArray alloc]init];
[self getdails]; //this get the longitude and latitude fr
}
-(void) getdails
{
NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:#"http://www.cbapcertprep.com/service/index.php?/Download_vehicletrack/DownloadTrackData/35170"]];
[request setHTTPMethod:#"GET"];
[request setValue:#"application/json;charset=UTF-8" forHTTPHeaderField:#"content-type"];
NSError *err;
NSURLResponse *response;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData:responseData options: NSJSONReadingMutableContainers error: &err];
for (int i=0; i<[jsonArray count]; i++)
{
NSString *strlong=[[jsonArray objectAtIndex:i]objectForKey:#"longitude"];
NSString *strlat=[[jsonArray objectAtIndex:i]objectForKey:#"latitude"];
[getlong addObject: strlong];
[getlot addObject: strlat];
}
[self.yourtableview reloaddata];
}
#pragma mark - tablevie data source
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [getlong count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ;
}
cell.textlabel.text=[getlot objectAtIndex:indexPath.row];
cell.detailTextLabel.text=[getlong objectAtIndex:indexPath.row];
return cell;
}
Just using JSON Parsing do following:
for(NSDictionary *dict in dataArray)
{
NSLog(#"latitude %#",[dict objectForKey:#"latitude"]);
NSLog(#"longitude %#",[dict objectForKey:#"longitude"]);
}
I am having an issue reloading my tableView when calling from an outside class to start a method and reload the tableView
More specifically:
Here is the call from the outside class:
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
NSInteger tag = cell.tag;
impact* myScript = [[impact alloc] init];
[myScript startProcess:tag];
}
**From here** it moves to the `impact` class and loads the `startProcess` method:
- (void)startProcess:(NSInteger)number {
NSInteger testing = number;
cellID = testing;
// MAKE REQuEST TO SERVER
[self makeRequests];
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
}
This is the makeRequests method it calls:
-(void)makeRequests
{
/* GRAB USERNAME TO BE SENT OVER FOR NOTIFICATIONS */
NSArray *get = [[SSKeychain allAccounts] init];
//NSLog(#"get%#", get);
NSString *username = [get[0] objectForKey:#"acct"];
//if(cellID != 0)
//{
NSDictionary *dictionary = #{#"function": #"populateNotfications", #"username" : username};
NSError *error = nil;
NSData *data = [NSJSONSerialization dataWithJSONObject:dictionary options:0 error:&error];
NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
if (error)
NSLog(#"%s: JSON encode error: %#", __FUNCTION__, error);
NSURL *url = [NSURL URLWithString:#"test.com/dev/iphone/test.php"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:#"POST"];
NSString *params = [NSString stringWithFormat:#"json=%#",
[string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSData *paramsData = [params dataUsingEncoding:NSUTF8StringEncoding];
[request addValue:#"8bit" forHTTPHeaderField:#"Content-Transfer-Encoding"];
[request addValue:#"application/x-www-form-urlencoded" forHTTPHeaderField:#"Content-Type"];
[request addValue:[NSString stringWithFormat:#"%lu", (unsigned long)[paramsData length]] forHTTPHeaderField:#"Content-Length"];
[request setHTTPBody:paramsData];
// issue the request
NSURLResponse *response = nil;
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if (error)
NSLog(#"%s: NSURLConnection error: %#", __FUNCTION__, error);
// GRAB STATUS OBJECT
NSDictionary* json = [NSJSONSerialization
JSONObjectWithData:returnData //1
options:kNilOptions
error:&error];
self.impactsGrabed = [json objectForKey:#"requested_data"];
//}
}
Now from here it will run my tableView methods as shown below:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.impactsGrabed count];
}
- (double) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 75;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"timelineCell";
impactTimelineCell *cell = (impactTimelineCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell = [[impactTimelineCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
[cell initTimelineCell];
cell.statusLabel.text = [self.impactsGrabed[indexPath.row] objectForKey:#"message"];
cell.timestampLabel.text = [self.impactsGrabed[indexPath.row] objectForKey:#"time_post"];
return cell;
}
I have logged every method and every method works until I hit cellForRowAtIndexPath where nothing happens than. Nothing is returning void. Now heres the thing:
When calling the function startProcess from another class that starts the whole process of loading the tableView cells it does not work. If I call the startProcess method inside the viewDidLoad in that file on initiation the tableView cells load properly.
So for example:
If I place [self startProcess:1]; within the viewDidLoad it works perfect! If I call [myScript startProcess:tag]; from the other class, it wont work properly.
What do you guys think the issue is?
Since all your controller are already instantiated and on screen, you don't need to instantiate one (and indeed you shouldn't since that creates a new instance that's not on screen).
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
NSInteger tag = cell.tag;
impact* myScript = self.parentViewController.childViewControllers[1]; // if my script is one of the child view controllers, then this is how you need to access it -- the number might be 0,1 or 2 depending on which one is the impact controller
[myScript startProcess:tag];
}
You can also do this in prepareForSegue -- when your controller is instantiated, all the embedded child controllers will also be, and you can get a reference to them from the destinationViewController property of the segue.
Because this controller is already on screen, it's ok to call reloadData where you do in startProcess.