0

I'm new in programming, and still don't understand some things. Please help me with this. I have created two textField's and one button on my first ViewController. button calculate values from this two textField's. I want to store this result to tableView in second ViewController in my Storyboard. How can i send this values (NSString) to another .h file and create new cell in tableView with text (result from textField's)

this is my IBAction for button:

     - (IBAction)pocitadloSpotreby:(UIButton*)pripocitaj{

        double value1 = [litre.text doubleValue];

        double value2 = [kilometre.text doubleValue];

        double result = (value1 / value2) * 100;

       self.display.text = [NSString stringWithFormat:@"%.2lf", result];
       }

and this is my .m file where i have tableView (and of course UITableViewDelegate, UITableViewDataSource:

    @interface FlipsideViewController ()
   {

   NSMutableArray *novyZaznam;
   }


   @end



   @implementation FlipsideViewController


   - (void)viewDidLoad
   {

   [super viewDidLoad];

   novyZaznam = [[NSMutableArray alloc]init];


// Do any additional setup after loading the view, typically from a nib.
  }

  - (void)didReceiveMemoryWarning
  {
  [super didReceiveMemoryWarning];
  // Dispose of any resources that can be recreated.
  }
  - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  {

  return 1;
  }

  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  {

   return novyZaznam.count;
  }

   - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:        (NSIndexPath *)indexPath
  {

  static NSString *CellIdentifier = @"Cell";

 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

 if (!cell) {

 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault  reuseIdentifier:CellIdentifier];

 }


 NSString *cellValue = [novyZaznam objectAtIndex:indexPath.row];

 cell.textLabel.text = cellValue;


 return cell;
 }

 @end

I dont know how can i insert new row (cell) into my tableView with text from textField and result NSString.

Thank you for any help!

Wain
  • 118,658
  • 15
  • 128
  • 151
Mayo323
  • 288
  • 3
  • 10

1 Answers1

0

Try to follow the procedure in the answer: https://stackoverflow.com/a/9736559/2670912. Since you are using storyboards try the first option. In my opinion it is the easiest to use.

Community
  • 1
  • 1
  • Thank you for that. I have searched just for some TableView words :) will try it in few hours. Hope will works . – Mayo323 Sep 02 '13 at 07:21
  • I already done my app and everything work fine, but when i close it in multitask view app will start without my created tablecells ...what i have to do? save my NSMutableArray into som plist? – Mayo323 Sep 03 '13 at 16:15
  • I think it would be best to submit that as a new question. – WeekendCodeWarrior Sep 04 '13 at 22:22