There is 5 elements in an array , in that 2 elements have data and another elements are blank and in tableview it show both element but when i scroll the app crash.i have to show menu_name in the section and its working but when i scroll tableview the app crash because, so can any one give me the solution?
Here is the Response which i have to show in tableview
"status":"true",
"message":"food point menu available",
"data":[
{
"menu_id":"9",
"menu_name":"Morning Menu",
"food_list":[
{
"food_name":"Brigadeiros",
"foodtype":"Pastas",
"food_per_person":"20",
"food_bonus":"packing"
},
{
"food_name":"Cachaca",
"foodtype":"Pastas",
"food_per_person":"30",
"food_bonus":"packing"
}
]
},
{
"menu_id":"10",
"menu_name":"Afternoon Menu",
"food_list":[
{
"food_name":"Quindim",
"foodtype":"Pastas",
"food_per_person":"30",
"food_bonus":"packing"
},
{
"food_name":"Cachaca",
"foodtype":"Pastas",
"food_per_person":"30",
"food_bonus":"packing"
}
]
},
{
"menu_id":"12",
"menu_name":"Evening Menu",
"food_list":""
},
{
"menu_id":"17",
"menu_name":"MenuSegundaFeira",
"food_list":""
},
{
"menu_id":"18",
"menu_name":"MenuTercaFeira",
"food_list":""
}
]
}
And this is the code which i have written in my app
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if([FinalArrayCategory count]>0) {
return [[[FinalArrayCategory objectAtIndex:0] objectForKey:#"food_list"] count];
}
else
{
return 0;
}
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
if([FinalArrayCategory count]>0) {
return [[FinalArrayCategory valueForKey:#"menu_name"] count];
}
else
{
return 0;
}
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
NSString *sectionName;
sectionName =[[FinalArrayCategory valueForKey:#"menu_name"] objectAtIndex:section];
return sectionName;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
MenuListCELL *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.lblpice.text=[[[[FinalArrayCategory objectAtIndex:indexPath.section]objectForKey:#"food_list"] valueForKey:#"food_name"]objectAtIndex:indexPath.row];
// cell.lblType.text=[[FinalArrayCategory valueForKey:#"category_name"] objectAtIndex:indexPath.row];
// cell.lblBonus.text=[[FinalArrayCategory valueForKey:#"food_bonus"] objectAtIndex:indexPath.section];
// cell.lblFoodName.text=[[FinalArrayCategory valueForKey:#"menu_name"] objectAtIndex:indexPath.section];
//
// NSString *pickURL=[[FinalArrayCategory valueForKey:#"food_image"] objectAtIndex:indexPath.section];
// [cell.lblImage sd_setImageWithURL:[NSURL URLWithString:pickURL] placeholderImage:[UIImage imageNamed:#"itemplaceholder.jpg"] options:SDWebImageProgressiveDownload progress:^(NSInteger receivedSize, NSInteger expectedSize) {
// } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
// }];
return cell;
}
return [[[FinalArrayCategory objectAtIndex:0] objectForKey:#"food_list"] count];
change objectAtIndext from 0 to IndexPath.section
Please try this code..
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[[FinalArrayCategory objectAtIndex:section] objectForKey:#"food_list"] count];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [FinalArrayCategory count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
NSString *sectionName;
sectionName =[[FinalArrayCategory objectAtIndex:section] objectForKey:#"menu_name"];
return sectionName;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
MenuListCELL *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if ([[[FinalArrayCategory objectAtIndex:indexPath.section] objectForKey:#"food_list"] iskindOfClass:[NSArray class]]) {
NSDictionary *dictData=[[[FinalArrayCategory objectAtIndex:indexPath.section] objectForKey:#"food_list"] objectAtIndex:indexPath.row];
cell.lblpice.text=[dictData objectForKey:#"food_name"];
}else{
cell.lblpice.text=#"";
}
return cell;
}
And let me know its working or not.
Happy Coding!!
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
MenuListCELL *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if([FinalArrayCategory objectAtIndex:indexPath.section]objectForKey:#"food_list"].count>0){
NSString *foodName =[[[[FinalArrayCategory objectAtIndex:indexPath.section]objectForKey:#"food_list"] valueForKey:#"food_name"]objectAtIndex:indexPath.row];
if(foodName){
cell.lblpice.text=foodName;
}
}else{
cell.lblpice.text=#"";
}
return cell;
}
please try this
Related
Two bug in this code.
First one when i delete Row in tableview delete last row not selected row.
Second Bug is when try to delete more than one row that time will delete successfully but when reload tableview Only one row deleted. Rest row will appear again.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return result.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell" forIndexPath : indexPath];
if (!(cell == nil)) {
name = (UILabel *)[cell viewWithTag:10];
name.text = [result objectAtIndex : indexPath.row];
}
name.tag=indexPath.row;
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (IBAction)action:(id)sender {
[_myTableView setEditing:YES animated:YES];
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleDelete;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell" forIndexPath : indexPath];
if (!(cell == nil)) {
name = (UILabel *)[cell viewWithTag:10];
name.text = [result objectAtIndex : indexPath.row];
}
name.tag=indexPath.row;
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) {
[result removeObjectAtIndex:indexPath.row];
[tableView reloadData];
[spinner startAnimating];
NSString *id = [profile objectForKey:#"user_id"];
NSString *tb =tid;
NSString *string = [NSString stringWithFormat:#"userid=%#&topiid=%#",id,tb];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:#"myDeleteUrl"]];
NSData *data = [string dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
[request setHTTPMethod:#"POST"];
[request setHTTPBody : data];
NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration
defaultSessionConfiguration]]; [[session dataTaskWithRequest : request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSDictionary *JSON= [NSJSONSerialization JSONObjectWithData :data options :NSJSONReadingMutableContainers error: nil];
NSArray *alertArray = [JSON objectForKey:#"deletebookmark"];
for (NSDictionary *alert in alertArray ){
if ([[alert objectForKey:#"status"] isEqualToString:#"done"]) {
NSLog(#"done");
[spinner stopAnimating];
}
else{
NSLog(#"notDone");
[spinner stopAnimating];
}
}
}]resume];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell" forIndexPath : indexPath];
if (!(cell == nil)) {
name = (UILabel *)[cell viewWithTag:10]; name.text = [result objectAtIndex : indexPath.row];
}
name.tag=indexPath.row;
return cell;
}
In this datasource method, you have used a "if" condition, and due to your cell is reusable cell, so you have to use the else part too in this data source method.
Like
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell" forIndexPath : indexPath];
if (!(cell == nil)) {
name = (UILabel *)[cell viewWithTag:10]; name.text = [result objectAtIndex : indexPath.row];
}
else{
name.tag=indexPath.row;
}
return cell;
}
Thanks
Try this way
[result removeObjectAtIndex:indexPath.row];
[tableView reloadData];// comment this line above code
[spinner stopAnimating];
//After that you can add
[tableView reloadData]; // above stopanimating line.
Add this cellForRowAtIndexPath method
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell" forIndexPath : indexPath];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:#"cell"];
}
name = (UILabel *)[cell viewWithTag:10];
name.text = [result objectAtIndex : indexPath.row];
name.tag=indexPath.row;
return cell;
}
I have Implemented multi select row but what i have to do is when we click on row it will move on another section , Here's my code what i have tried is ?
can anyone help me out from this ? Thanks in advance ...
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2; //assuming you have only two sections
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == 0)
return self.firstSectionDataSource.count;
else if (section == 1)
return self.dataArray.count;
else
return 0;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Here, Have to move row to another section while clcking ..
// other multiselect code
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Configure a cell to show the corresponding string from the array.
static NSString *kCellID = #"cellID";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellID];
cell.textLabel.text = [self.dataArray objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
#try {
NSMutableArray *sourceArray = nil;
if (sourceIndexPath.section == 0) {
sourceArray = self.firstSectionDataSource;
}
else if (sourceIndexPath.section == 1)
{
sourceArray = self.dataArray;
}
NSMutableArray *destinationArray = nil;
if (destinationIndexPath.section == 0) {
destinationArray = self.firstSectionDataSource;
}
else if (destinationIndexPath.section == 1)
{
destinationArray = self.dataArray;
}
NSString *stringToMov = [sourceArray objectAtIndex:sourceIndexPath.row];
[sourceArray removeObject:stringToMov];
[destinationArray insertObject:stringToMov atIndex:destinationIndexPath.row];
}
#catch (NSException *exception) {
NSLog(#"exception = %# \n reason = %#",exception,exception.reason);
}
}
In cellForRowAtIndexPath
[cell setShowsReorderControl:YES];
And you need to implement the following UITableView delegate and data source methods properly
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2; //assuming you have only two sections
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == 0)
return firstSectionDataSource.count;
else if (section == 1)
return secondSectionDataSource.count;
else
return 0;
}
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
#try {
NSMutableArray *sourceArray = nil;
if (sourceIndexPath.section == 0) {
sourceArray = firstSectionDataSource;
}
else if (sourceIndexPath.section == 1)
{
sourceArray = secondSectionDataSource;
}
NSMutableArray *destinationArray = nil;
if (destinationIndexPath.section == 0) {
destinationArray = firstSectionDataSource;
}
else if (destinationIndexPath.section == 1)
{
destinationArray = secondSectionDataSource;
}
NSString *stringToMov = [[sourceArray objectAtIndex:sourceIndexPath.row] retain];
[sourceArray removeObject:stringToMov];
[destinationArray insertObject:stringToMov atIndex:destinationIndexPath.row];
[stringToMov release];
}
#catch (NSException *exception) {
NSLog(#"exception = %# \n reason = %#",exception,exception.reason);
}
}
You can do the next:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView moveRowAtIndexPath:indexPath toIndexPath:[NSIndexPath indexPathForRow:row inSection:section]];
// other multiselect code
}
Try this -
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjects:[NSArray arrayWithObjects:[NSArray arrayWithObjects:#"a",#"b",#"c", nil],[NSArray arrayWithObjects:#"d",#"e",#"f", nil], nil] forKeys:[NSArray arrayWithObjects:#"firstSection",#"secondsection", nil]];
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [[dict allKeys] count]; //assuming you have only two sections
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[dict objectForKey:[dict allKeys][section]] count];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSMutableArray *arr = [dict objectForKey:[dict allKeys][indexPath.section]];
NSString *str = arr[indexPath.row];
if (indexPath.row!=0) {
[arr removeObject:str];
}
NSMutableArray *arr1 = [dict objectForKey:[dict allKeys][0]];
[arr1 addObject:str];
[tableView reloadData];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSArray *arr = [dict objectForKey:[dict allKeys][indexPath.section]];
NSString *str = arr[indexPath.row];
static NSString *kCellID = #"cellID";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellID];
cell.textLabel.text = str;
return cell;
}
i am newbie in iOS and i know this Question is asked for many times but i am not getting solution.i made an application with tableview here is my tableview code Containing two section and i want to Fill this section with JSON Data.i made Two CustomCell. it Display well but i am not able to fill my JSON Parsing Data.
my code is.
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0)
{
static NSString *CellIdentifierOne=#"CellOne";
CustumCell *cellOne =[tableView dequeueReusableCellWithIdentifier:CellIdentifierOne];
if (cellOne == nil)
{
NSArray *nibOne=[[NSBundle mainBundle]loadNibNamed:#"CustumCell" owner:self options:nil];
cellOne=[nibOne objectAtIndex:0];
cellOne.userInteractionEnabled=NO;
}
{
[cellOne.spinner startAnimating];
NSDictionary *dict = [self.imageArray objectAtIndex:indexPath.section];
NSString *img2=[dict valueForKey:#"front_image"];
[cellOne.storeImage sd_setImageWithURL:[NSURL URLWithString:[img2 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage:[UIImage imageNamed:#"Setting.png"] options:SDWebImageHighPriority completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL)
{
[cellOne.spinner stopAnimating];
cellOne.spinner.hidesWhenStopped=YES;
}];
}
return cellOne;
}
else
{
static NSString *CellIdentifierTwo=#"CellTwo";
TableCell *cellTwo=[tableView dequeueReusableCellWithIdentifier:CellIdentifierTwo];
if (cellTwo == nil)
{
NSArray *nibTwo=[[NSBundle mainBundle]loadNibNamed:#"TableCell" owner:self options:nil];
cellTwo=[nibTwo objectAtIndex:0];
cellTwo.userInteractionEnabled=NO;
}
return cellTwo;
}
return nil;
}
And Here Tableview section is Two and also code for numberofRow is
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == 0)
{
return 1;
NSLog(#"Images %#",self.imageArray);
}
else
{
return self.imageArray.count - 1;
}
}
when there is no any Data then it Shows as i want, but i am not able to fill my Data Please provide me any Solution.
#AshishGabani
look at the below code, what i understand for your requirement
I have taken an array, contains values like this
NSMutableArray *imageArray = [[NSMutableArray alloc]initWithObjects:#"1",#"2",#"3",nil];
Next TableView Methods:
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section==0) return 1;
return imageArray.count-1;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *simpleTableIdentifier = #"Simple";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
if(indexPath.section==0) {
cell.textLabel.text = [imageArray objectAtIndex:indexPath.row];
} else {
cell.textLabel.text = [imageArray objectAtIndex:indexPath.row+1];
}
return cell;
}
Just Comment you existing code and Copy this code and Paste your Xcode ViewController and Run the simulator, I think i reached your requirement .
Here is my problem I had a table view which consists of 3 three labels in it (test1, test2, test3) which comes from webservice. I want to load all the three labels in a single table view. Here is my code below :
for (NSDictionary *entry in entries) {
projectNames = [entries valueForKey:#"NM_PROJECT"];
taskNames = [entries valueForKey:#"TASk_NAME"];
subtaskNames = [entries valueForKey:#"SUBTASK_NAME"];
}
NSLog(#"project : %#", projectNames);
NSLog(#"taskNames : %#", taskNames);
NSLog(#"subtask : %#", subtaskNames);
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
// Return the number of sections.
return 1;
}
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [projectNames count];
}
-(UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identitifier = #"Cell";
DLPTSTableViewCell * cell = [tableView
dequeueReusableCellWithIdentifier:identitifier
forIndexPath:indexPath];
long row = [indexPath row];
cell.textLabel.text = projectNames[row];
cell.textLabel.text = taskNames[row];
cell.textLabel.text = subtaskNames[row];
return cell;
}
I want to load the test 1 in projectnames array, test 2 in tasknames array and test 3 in subtasks arrays..
Please help me out.
If you are creating custom UITableViewCell with name "DLPTSTableViewCell" then first create three labels i.e yourLabel1, yourLabel2, yourLabel3 and use this below code :
-(DLPTSTableViewCell *)getNewCell
{
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:#"DLPTSTableViewCell" owner:nil options:nil];
DLPTSTableViewCell *cell;
for (id currentObject in topLevelObjects)
{
if ([currentObject isKindOfClass:[DLPTSTableViewCell class]])
{
cell= (DLPTSTableViewCell *)currentObject;
return cell;
}
}
return nil;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"CustomCell";
DLPTSTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [self getNewCell];
}
// for displaying values
cell.yourLabel1.text = your first value;
cell.yourLabel2.text = your second value;
cell.yourLabel3.text = your third value;
return cell;
}
Here's my code:
- (void)viewDidLoad
{
[super viewDidLoad];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.domain.com/venues.php"]];
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSError *error = nil;
NSArray *responseArray = [NSJSONSerialization JSONObjectWithData:response options:0 error:&error];
NSLog(#"%#", responseArray); // This logs fine
}
#synthesize responseArray;
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return 1; // temporary replacement for return [responseArray count] for testing purposes
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier =#"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.textLabel.text=[responseArray objectAtIndex:indexPath.row];
return cell;
}
For comparison, the following code does work:
- (void)viewDidLoad
{
[super viewDidLoad];
self.colors= [[NSArray alloc] initWithObjects: #"Red", #"Yellow", #"Green", #"Blue", #"Purple", nil];
NSLog(#"%#", self.colors); // logs fine
}
#synthesize colors;
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.colors count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier =#"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.textLabel.text=[self.colors objectAtIndex:indexPath.row];
return cell;
}
Update
My cellForRowAtIndexPath now looks like this, but I'm still not getting any results. Is there a problem with my JSON?
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier =#"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.textLabel.text=[[self.responseArray objectAtIndex:indexPath.row]objectForKey:#"name"];
return cell;
}
JSON:
[{"name":"venue 1"},{"name":"venue 2"},{"name":"venue 3"}]
#interface YourTableViewController ()<BViewControllerDelegate>
#property (strong, nonatomic) NSArray *responseArray;
#end
#implementation yourTableViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.responseArray = [NSJSONSerialization JSONObjectWithData:response options:0 error:&error];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.responseArray count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier =#"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.textLabel.text=[[self.responseArray objectAtIndex:indexPath.row]objectForKey:#"yourKey"];
return cell;
}