user5594892
user5594892

Reputation:

Condition doesn't work

I use button in ViewController to go TableViewController. In TableViewController I create int NInt1. But when I go to TableViewController condition doesn't work.

ViewController.m

- (IBAction)Button:(id)sender {
MasterViewController *trns =[[MasterViewController alloc]init];
[_Button.titleLabel.text isEqualToString:@"1"];
    trns.NInt1=1;
}

TableViewController.m

 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(_NInt1 == 1){
    return 5;
}else{
    return 20;
}
}

Upvotes: 1

Views: 64

Answers (4)

user3182143
user3182143

Reputation: 9599

I tried the solution.Finally I got.Thank you.The condition has worked now.

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
  if([segue.identifier isEqualToString:@"goTableViewController"])
  {
    TableViewController *tableVC = (TableViewController *) segue.destinationViewController;
    tableVC.NInt1 = 5;
  }
}

Upvotes: 0

Michaël Azevedo
Michaël Azevedo

Reputation: 3896

If you use storyboard, then the destination view controller is not created from your IBAction. It can be verified easily : you never push or present the newly created view controller, which is local in your method.

Instead use prepareForSeguemethod as described in Jaimish answer.

Upvotes: 0

Jaimish
Jaimish

Reputation: 629

If you are using the story pass the value like this:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    RecipeDetailViewController *destViewController = segue.destinationViewController;
    destViewController.NInt1 = 1;
}

Now see the value of NInt in viewDidLoad of your destination view controller.

Upvotes: 1

Shangari C
Shangari C

Reputation: 772

I think you need to modify like

- (IBAction)Button:(UIButton *)sender {
 MasterViewController *trns =[[MasterViewController alloc]init];
if [sender.titleLabel.text isEqualToString:@"1"]{
  trns.NInt1=1;
 }
}

on that tableviewController viewDidload check like use NSLog for the object is 1 or not

Upvotes: 0

Related Questions