JSON Data in UITableViewCell - ios

Hi I am developing one quizz app and the issue is, I have the following JSON Data, which is a respond from my WebService.
[
{
"id": "3",
"question": "tes!2t",
"option1": "test",
"option2": "test",
"option3": "test",
"option4": "test",
"correct_answer": "test",
"explanation": "test",
"image": "test",
"created_at": "2014-09-23 02:00:00",
"updated_at": "2014-09-09 06:19:28"
}
]
How can I display the Data option1,option2,option3 and option4 in a TableViewCell.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 4;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:#"MyCell"];
if (cell==nil)
{
cell=[[UITableViewCell alloc]initWithFrame:CGRectZero];
}
NSString *urlString = #"http://localhost/quiz/public/questions";
NSData *JSONData = [NSData dataWithContentsOfFile:urlString:NSDataReadingMappedIfSafe error:nil];
NSDictionary *jsonObject = [NSJSONSerialization JSONObjectWithData:JSONData options:NSJSONReadingMutableContainers error:nil];
NSArray *array = [jsonObject objectForKey:#"questions"];
questions = [[NSMutableArray alloc] initWithCapacity:[array count]];
//choices = [[NSArray alloc] init];
for (NSDictionary *dict in array) {
question = [[Questions alloc] initWithObject:dict];
[questions addObject:question];
}
cell.textLabel.text = [choices objectAtIndex:indexPath.row];
cell.textLabel.font=[UIFont fontWithName:#"Bold" size:12];
cell.backgroundColor=[UIColor grayColor];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
int selectedRow = indexPath.row;
NSString *filePathChoices = [[NSBundle mainBundle] pathForResource:#"questions" ofType:#"json"];
NSData *JSONDataChoices = [NSData dataWithContentsOfFile:urlString
:NSDataReadingMappedIfSafe error:nil];
NSMutableDictionary *jsonObjectChoices = [NSJSONSerialization JSONObjectWithData:JSONDataChoices options:NSJSONReadingMutableContainers error:nil];
Any help would be appreciated. Thanks in advance !

Try this hopefully it will works:
NSString *urlString = #"your URL";
NSURL *url = [NSURL URLWithString:urlString];
NSData *data = [NSData dataWithContentsOfURL:url];
NSError *error;
jsonObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
jsonDict11 = [jsonObject valueForKey:#"question"];
NSLog(#"array %#",jsonDict11);
NSLog(#"Count : %d", [jsonDict11 count]);
Questionscount=[jsonDict11 count];
self.QuestionsText.text=[jsonDict11 objectAtIndex:ii];
In TableView:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:#"MyCell"];
if (cell==nil)
{
cell=[[UITableViewCell alloc]initWithFrame:CGRectZero];
}
NSArray *jsonDict1=[jsonObject valueForKey:#"option1"];
NSArray *jsonDict2=[jsonObject valueForKey:#"option2"];
NSArray *jsonDict3=[jsonObject valueForKey:#"option3"];
NSArray *jsonDict4=[jsonObject valueForKey:#"option4"];
NSString *str1=[jsonDict1 objectAtIndex:ii];
NSString *str2=[jsonDict2 objectAtIndex:ii];
NSString *str3=[jsonDict3 objectAtIndex:ii];
NSString *str4=[jsonDict4 objectAtIndex:ii];
nameArr = [NSArray arrayWithObjects:str1,str2,str3,str4,nil];
cell.textLabel.text = [nameArr objectAtIndex:indexPath.row];
return cell;
}

Try this:
NSString *jsonString = #"[{\"id\":\"3\",\"question\":\"tes!2t\",\"option1\":\"test\",\"option2\":\"test\",\"option3\":\"test\",\"option4\":\"test\",\"correct_answer\":\"test\",\"explanation\":\"test\",\"image\":\"test\",\"created_at\":\"2014-09-23 02:00:00\",\"updated_at\":\"2014-09-09 06:19:28\"}]";
Pass your json string ("jsonString")
NSData *aDataJson = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSError *aError = nil;
NSArray *aArrJson = [NSJSONSerialization JSONObjectWithData:aDataJson options:NSJSONReadingMutableContainers error: &aError];
NSLog(#"%#",aArrJson);
NSLog(#"%#",[[aArrJson objectAtIndex:0] objectForKey:#"question"]);

Related

how to display the key to the tableview

how to display the key on tableview at the same time?
Here I can display the value.
I want to show the key on cell.textLabel setText:#"A"
Please..
.
.
.
Here is my code
ThankYou
Thankyou very much.
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:#"https://reserve.cdn-apple.com/AU/en_AU/reserve/iPhone/availability.json"]];
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
_listarr = [[NSMutableArray alloc]init];
id list = [dic objectForKey:self.strStore];
if ([list isKindOfClass:[NSDictionary class]]) {
NSDictionary *dictionary = (NSDictionary *)list;
NSArray *keys = [list allKeys];
for (NSString *key in keys) {
NSString *teamname = (NSString *)[dictionary objectForKey:key];
NSLog(#"",key);
[_listarr addObject:[NSString stringWithFormat:#"%#", teamname]];
}
} else {
// Do some error handling
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//必须返回与数据容器一样的数量,否则会报数据越界错
return [_listarr count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"thisCell";
UITableViewCell *cell;
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
[cell.textLabel setText:#"A"];
[cell.detailTextLabel setText:[_listarr objectAtIndex:indexPath.row]];
return cell;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
#end
Hi this code will give you what you required I think..
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
NSArray *array = [dic allKeys];
NSArray *temparray = [dic objectsForKeys:array notFoundMarker:[NSNull null]];
Use NSDictionary's allKeysForObject: to look up keys that match an object. Objects are compared with isEqual: and should match for simple NSStrings.
If the array is too large, this may be slow, in which case you might create another array with the key values that you can index quickly.

Using NSMutableArray in TableViewController with JSON data

Good afternoon,
I'm trying to use a NSMutableArray in my TableViewController from a JSON output and I'm a little bit lost because currently I can store my JSON data in a NSMutableArray, and I have checked with a NSLog that the content is OK, but now I have to show that data in my TableViewController and that's when I'm lost.
I'm using an another example of TableViewController using NSArray but now I have to modify it for a NSMutableArray. If you can help me with some code or show me some examples or tutorials I will be much appreciated.
I know in my code maybe I have something wrong because I'm using an old example using only NSArray but I'm showing you because that's what I don't know how to do, I need to work with NSMutableArray and that's why I'm asking for your help.
How can I show a NSMutableArray in my TableViewController?
- (void)viewDidLoad
{
[super viewDidLoad];
[self fetchJson];
}
-(void)fetchJson {
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
NSString * urlString = [NSString stringWithFormat:#"http://website.com/service.php"];
NSURL * url = [NSURL URLWithString:urlString];
NSData * data = [NSData dataWithContentsOfURL:url];
//NSError * error;
//NSMutableArray *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
// I advice that you make your carModels mutable array and initialise it here,before start working with json
//self.carModels = [[NSMutableArray alloc] init];
NSMutableArray *carModels=[[NSMutableArray alloc]init];
NSMutableArray *carMakes=[[NSMutableArray alloc]init];
NSMutableArray *carImages=[[NSMutableArray alloc]init];
#try
{
NSError *error;
NSMutableArray* json = [NSJSONSerialization
JSONObjectWithData:data
options:NSJSONReadingMutableContainers|NSJSONReadingMutableLeaves
error:&error];
if (error)
{
NSLog(#"%#",[error localizedDescription]);
}
else
{
for(int i=0;i<json.count;i++)
{
NSDictionary * jsonObject = [json objectAtIndex:i];
NSString* imagen = [jsonObject objectForKey:#"imagen"];
[carImages addObject:imagen];
NSDictionary * jsonObject2 = [json objectAtIndex:i];
NSString* user = [jsonObject2 objectForKey:#"user"];
[carMakes addObject:user];
NSDictionary * jsonObject3 = [json objectAtIndex:i];
NSString* images = [jsonObject3 objectForKey:#"date"];
[carModels addObject:images];
}
}
}
#catch (NSException * e)
{
NSLog(#"Exception: %#", e);
}
#finally
{
NSLog(#"finally");
// That's showing the data "1, 2, 3".
NSLog(#"models: %#", carModels);
NSLog(#"makes: %#", carMakes);
NSLog(#"images: %#", carImages);
}
}
);
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.carModels count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"carTableCell";
CarTableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[CarTableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
// Configure the cell...
cell.makeLabel.text = [_carMakes objectAtIndex: [indexPath row]];
cell.modelLabel.text = [self.carModels objectAtIndex:[indexPath row]];
UIImage *carPhoto = [UIImage imageNamed: [self.carImages objectAtIndex: [indexPath row]]];
cell.carImage.image = carPhoto;
return cell;
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"ShowCarDetails"])
{
CarDetailViewController *detailViewController =
[segue destinationViewController];
NSIndexPath *myIndexPath = [self.tableView
indexPathForSelectedRow];
detailViewController.carDetailModel = [[NSArray alloc]
initWithObjects: [self.carMakes
objectAtIndex:[myIndexPath row]],
[self.carModels objectAtIndex:[myIndexPath row]],
[self.carImages objectAtIndex:[myIndexPath row]],
nil];
}
}
Thanks.
Declare NSMutableArray *jsonArray ; as global
-(void)fetchJson {
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
NSString * urlString = [NSString stringWithFormat:#"http://website.com/service.php"];
NSURL * url = [NSURL URLWithString:urlString];
NSData * data = [NSData dataWithContentsOfURL:url];
//NSError * error;
//NSMutableArray *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
// I advice that you make your carModels mutable array and initialise it here,before start working with json
//self.carModels = [[NSMutableArray alloc] init];
#try
{
NSError *error;
[jsonArray removeAllObjects];
jsonArray = [NSJSONSerialization
JSONObjectWithData:data
options:NSJSONReadingMutableContainers|NSJSONReadingMutableLeaves
error:&error];
}
#catch (NSException * e)
{
NSLog(#"Exception: %#", e);
}
#finally
{
[self.tableView reloadData]
}
}
);
}
To Display The TableView Like This
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [jsonArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"carTableCell";
CarTableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[CarTableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
// Configure the cell...
cell.makeLabel.text = [[jsonArray objectAtIndex:indexPath.row] valueForKey:#"imagen"];
cell.modelLabel.text = [[jsonArray objectAtIndex:indexPath.row] valueForKey:#"user"];
UIImage *carPhoto = [[jsonArray objectAtIndex:indexPath.row] valueForKey:#"date"];
cell.carImage.image = carPhoto;
return cell;
}
Add
[self.tableView reloadData]
after you have fetched and parsed the JSON.
Whenever you change table datas from different array just add [self.tableView reloadData] in you method.
It will remove old data & shows new data into your tableview.

Putting data from SONObjectWithData to UITableView

i am building a app in which i am getting data from a php file and already NSLoging it in xcode and it is showing data in this format:
jsonObject=(
(
1,
abc,
"abc#xyz.com",
"501 B3 Town"
),
(
2,
sam,
"sam#xyz.com",
"502 B3 Town"
),
(
3,
jhon,
"jhon#xyz.com",
"503 B Town"
)
)
and here is my viewdidload
- (void)viewDidLoad
{
[super viewDidLoad];
statuses=[[NSMutableArray alloc]init];
NSURL *myURL = [NSURL URLWithString:#"http://url/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 = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
}];
}
now i want to display all records in uitableview. can anyone tell me how can i do that. Thanks
check this tutorial out:
http://thedarkdev.blogspot.co.uk/2013/09/web-service-apps-in-ios7-json-with.html
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return myObject.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = #"Item";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell=[[UITableViewCell alloc]initWithStyle:
UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
NSDictionary *tmpDict = [myObject objectAtIndex:indexPath.row];
NSMutableString *text;
//text = [NSString stringWithFormat:#"%#",[tmpDict objectForKey:title]];
text = [NSMutableString stringWithFormat:#"%#",
[tmpDict objectForKeyedSubscript:title]];
NSMutableString *detail;
detail = [NSMutableString stringWithFormat:#"Author: %# ",
[tmpDict objectForKey:author]];
NSMutableString *images;
images = [NSMutableString stringWithFormat:#"%# ",
[tmpDict objectForKey:thumbnail]];
NSURL *url = [NSURL URLWithString:[tmpDict objectForKey:thumbnail]];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc]initWithData:data];
cell.textLabel.text = text;
cell.detailTextLabel.text= detail;
cell.imageView.frame = CGRectMake(0, 0, 80, 70);
cell.imageView.image =img;
return cell;
}
I This format is Array -> Array format in inner array may count is consistent (4) elements
Try This onece
No of row in Sections method take - jsonparsingarray count
Cell for row at index method
display like this ex: name and email id that index is 1 & 3
if ([[jsonparsingarray objectatindex:indexpath.row] count])
{
cell.textlable.text = [[jsonparsingarray objectatindex:indexpath.row]objectatindex:1];
cell.detailtextlable.text = [[jsonparsingarray objectatindex:indexpath.row]objectatindex:3];
}

NSInvalidArgumentException reason: data parameter is nil in UITableView while trying to display the Flickr images

Hi in my application I want to display the Flickr album list in UITableView so i have searched for long time and i have found some solution. I have used the method which given in the solution its not working its giving error like
NSInvalidArgumentException', reason: 'data parameter is nil
The solution link click here
And since I'm trying this for first time I'm not able resolve this issue. This is MY API LINK for Flickr
I have used this code to display the Flickr image Album list in UItableview
{
NSMutableArray *photoURLs;
NSMutableArray *photoSetNames;
NSMutableArray *photoid1;
}
My Flickr API key
#define FlickrAPIKey #"a6a0c7d5efccffc285b0fe5ee1d938e3"
- (void)viewDidLoad
{
[super viewDidLoad];
photoURLs = [[NSMutableArray alloc] init];
photoSetNames = [[NSMutableArray alloc] init];
photoid1 = [[NSMutableArray alloc] init];
[self loadFlickrPhotos];
}
My TableView code
- (void)loadFlickrPhotos
{
NSString *urlString = [NSString stringWithFormat:#"http://api.flickr.com/services/rest/?method=flickr.photosets.getList&api_key=%#&user_id=%#&per_page=10&format=json&nojsoncallback=1", FlickrAPIKey, #"124757153#N04"];
NSURL *url = [NSURL URLWithString:urlString];
NSString *jsonString = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
NSDictionary *results = [NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];
NSArray *photosets = [[results objectForKey:#"photosets"] objectForKey:#"photoset"];
for (NSDictionary *photoset in photosets) {
NSString *title = [[photoset objectForKey:#"title"] objectForKey:#"_content"];
[photoSetNames addObject:(title.length > 0 ? title : #"Untitled")];
NSString *photoid = [photoset objectForKey:#"id"];
[photoid1 addObject:photoid];
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [photoSetNames count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier =#"Cell";
flickrpoliticalCell *cell =(flickrpoliticalCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[flickrpoliticalCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.tit.text = [photoSetNames objectAtIndex:indexPath.row];
return cell;
}
try this
- (void)loadFlickrPhotos
{
//
NSString *urlString = [NSString stringWithFormat:#"https://www.flickr.com/services/rest/?method=flickr.photosets.getList&api_key=a6a0c7d5efccffc285b0fe5ee1d938e3&format=json&user_id=124757153#N04&per_page=10&nojsoncallback=1",nil];
NSLog(#"the url string==%#",urlString);
NSURL *url = [NSURL URLWithString:urlString];
NSString *jsonString = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
NSLog(#"the str==%#",jsonString);
NSDictionary *results = [NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];
NSArray *photosets = [[results objectForKey:#"photosets"] objectForKey:#"photoset"];
for (NSDictionary *photoset in photosets) {
NSString *title = [[photoset objectForKey:#"title"] objectForKey:#"_content"];
NSLog(#"title==%#",title);
[photoSetNames addObject:(title.length > 0 ? title : #"Untitled")];
NSString *primary = [photoset objectForKey:#"primary"];
NSString *server = [photoset objectForKey:#"server"];
NSString *secret = [photoset objectForKey:#"secret"];
NSString *farm = [photoset objectForKey:#"farm"];
NSString *urlstr=[NSString stringWithFormat:#"http://farm%#.staticflickr.com/%#/%#_%#.jpg",farm,server,primary,secret];
NSLog(#"your photo id==%#",urlstr);
[photoids addObject:urlstr];
}
}

output in tableview should be in each row,i am getting whole response in one row, remaining are blank

output in tableview should be in each row,i am getting whole response in one row, remaining rows are blank .so how to display each row with data from server in uitableview
i get o/p as below in tableview
aa,bbb,cc……
hi,hello,"",…
o/p should be as below
aa
hi
bbb
hello
cc
""
this is my response
[{"result":[{"request_id":1,"ticket_number":"P_101","email":"xx","user_id":4,"description":"fjdyhsrwgk","status":"initiated"},{"request_id":2,"ticket_number":"P_102","email":"yyy","user_id":4,"description":"hi","status":"initiated"},{"request_id":3,"ticket_number":"P_103","email":"aaa","user_id":4,"description":"hii","status":"initiated"},{"request_id":4,"ticket_number":"P_104","email":"bbb","user_id":4,"description":"aa..","status":"initiated"}]}]
how to get array of objects in result key
below is code
listOfCustomers = [[NSMutableArray alloc]init];
str= [[NSUserDefaults standardUserDefaults] valueForKey:#"user_id"];
NSString *strJson=[NSString stringWithFormat:#"userId=%#",str];
NSString *strlength=[NSString stringWithFormat:#"%d",[strJson length]];
NSURL *url=[NSURL URLWithString:#"url"];
NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];
[request addValue:#"text/html" forHTTPHeaderField:#"Content-Type"];
[request addValue:strlength forHTTPHeaderField:#"Content-Length"];
NSData *requestData=[strJson dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody:requestData];
[request setHTTPMethod:#"POST"];
NSError *err;
NSData *responseData=[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&err];
NSString *strResponse=[[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(#"response is %#",strResponse);
dict1=[NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingAllowFragments error:&err];
NSArray *results = [dict1 valueForKey:#"result"];
listOfCustomers = [NSMutableArray array];
for (NSDictionary * oneCustomer in results)
{
// Create a new Customer record
Attributes * newCustomer = [[Attributes alloc] init];
newCustomer.Customer_ID = [oneCustomer valueForKey:#"request_id"];
newCustomer.Company_Name = [oneCustomer valueForKey:#"ticket_number"];
newCustomer.City = [oneCustomer valueForKey:#"email"];
newCustomer.userId = [oneCustomer valueForKey:#"user_id"];
newCustomer.description = [oneCustomer valueForKey:#"description"];
newCustomer.createdTime = [oneCustomer valueForKey:#"createdTime"];
newCustomer.Status = [oneCustomer valueForKey:#"status"];
// Add our new Customer record to our NSMutableArray
[listOfCustomers addObject:newCustomer];
}
[tableVwTotalRequests reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [listOfCustomers count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier=#"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:#"identifier"];
}
Attributes* cust = [listOfCustomers objectAtIndex:indexPath.row];
cell.textLabel.text = [NSString stringWithFormat:#"%#",cust.Company_Name];
cell.detailTextLabel.text= [NSString stringWithFormat:#"%#",cust.description];
return cell;
}
Try this,
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier=#"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:#"identifier"];
}
Attributes* cust = [listOfCustomers objectAtIndex:indexPath.row];
NSString *companyName = [NSString stringWithFormat:#"%#",cust.Company_Name];
NSArray *companyNames = [companyName componentsSeparatedByString:#","];
cell.textLabel.text = [companyNames objectAtIndex:indexPath.row];
NSString *description = [NSString stringWithFormat:#"%#",cust.description];
NSArray *descriptions = [description componentsSeparatedByString:#","];
cell.detailTextLabel.text= [descriptions objectAtIndex:indexPath.row];
}
You are defining your identifier as #"cell", but in your cell initialiser you are passing in the reuse identifier of #"identifier". These should be the same, pass in the variable instead, not the name of the variable as a string.
You are also missing out returning your cell at the end of the method.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier=#"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
}
Attributes* cust = [listOfCustomers objectAtIndex:indexPath.row];
cell.textLabel.text = [NSString stringWithFormat:#"%#",cust.Company_Name];
cell.detailTextLabel.text= [NSString stringWithFormat:#"%#",cust.description];
return cell;
}

Resources