Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling api with different parameters on button click and passing it to cell for row it indexpath in iPhone
    primarykey
    data
    text
    <p>I have an application where I have a controller class which consist of a tableview inside in it. In the controller I have a searchbar and 5 buttons. When I run my application for the first time I want the first button to remain selected.</p> <p>When the button is clicked I am calling a JSON api from server and depending on the values returned from JSON I want to display in my tableview. When the second button is clicked the same function is called but by passing different parameter as id to it. I have done the code but the problem when the application is run for the first time the first button is shown selected and it's api is getting called but when I switch to next button my tableview does not get refreshed with the new values.</p> <p>I have 5 buttons which I have added to my to my controller class. When I run my application for the first time I want the first button to remain selected and its action to be performed and api to be called and when second button is clicked second action should be performed an so on and same should be reflected on tableview depending on results when particular button is clicked.</p> <p>This is my code:</p> <pre><code>- (void)viewDidLoad { category = [[ResultJson alloc] init]; dealsArray = [[NSMutableArray alloc] init]; [self.view bringSubviewToFront:btnAll]; [btnAll setBackgroundImage:[UIImage imageNamed:@"icon-1-active.png"] forState:UIControlStateNormal]; if ([[btnAll backgroundImageForState:UIControlStateNormal] isEqual:[UIImage imageNamed:@"icon-1-active.png"]]) { [self btnAll]; } [super viewDidLoad]; } -(IBAction)btnAll { [self.tblView reloadData]; NSLog(@"Done"); [self.view bringSubviewToFront:btnAll]; if (category.newArray) { [category.newArray release]; } category.newArray = [[NSMutableArray alloc] init]; [btnAll setUserInteractionEnabled:YES]; [btnAll setBackgroundImage:[UIImage imageNamed:@"icon-1-active.png"] forState:UIControlStateNormal]; [btnEntertainment setBackgroundImage:nil forState:UIControlStateNormal]; [btnRetail setBackgroundImage:nil forState:UIControlStateNormal]; [btnServices setBackgroundImage:nil forState:UIControlStateNormal]; [btnFood setBackgroundImage:nil forState:UIControlStateNormal]; [btnHealthBeauty setBackgroundImage:nil forState:UIControlStateNormal]; [category GetDetails:1]; [dealsArray addObjectsFromArray:category.newArray]; btnAll.tag = 0; } -(IBAction)btnEntertainment { [self.tblView reloadData]; [self.view bringSubviewToFront:btnEntertainment]; if (category.newArray) { [category.newArray release]; } category.newArray = [[NSMutableArray alloc]init]; [btnEntertainment setBackgroundImage:[UIImage imageNamed:@"icon-2-active.png"] forState:UIControlStateNormal]; [btnAll setBackgroundImage:nil forState:UIControlStateNormal]; [btnRetail setBackgroundImage:nil forState:UIControlStateNormal]; [btnHealthBeauty setBackgroundImage:nil forState:UIControlStateNormal]; [btnServices setBackgroundImage:nil forState:UIControlStateNormal]; [btnFood setBackgroundImage:nil forState:UIControlStateNormal]; [category GetDetails:2]; [dealsArray addObjectsFromArray:category.newArray]; btnEntertainment.tag = 1; } </code></pre> <p>This is my first 2 button action where I am calling the GetDetails api method by passing an id as a parameter to it. Initially in ViewDidload I am setting my first btnAll as selected and performing its action but the problem is when I click on the second button the results of the first button are shown on the tableview and on second time clicking the second button its results are visible in tableview.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload