#import "MasterViewController.h"

@interface MasterViewController()
- (NSInteger)fibonacci:(NSInteger)term;
@end

@implementation MasterViewController

- (void)viewDidLoad
{
   [super viewDidLoad];
}

- (void)viewWillAppear:(BOOL)animated
{
   [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
   [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
   [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
   [super viewDidDisappear:animated];
}

// okrelenie liczby sekcji w widoku tabeli
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
   return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
   return 35;
}

// dostosowanie wygldu komrki widoku tabeli
- (UITableViewCell *)tableView:(UITableView *)tableView
   cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   static NSString *CellIdentifier = @"Cell";

   UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
   if (cell == nil) {
      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                     reuseIdentifier:CellIdentifier] autorelease];
   }

   [[cell textLabel] 
      setText:[NSString stringWithFormat:@"%i", [self fibonacci:[indexPath row]]]];

   // konfiguracja komrki
   return cell;
}

- (void)tableView:(UITableView *)tableView
   didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}

- (void)didReceiveMemoryWarning
{
   // usunicie widokw, ktre nie maj widoku nadrzdnego
   [super didReceiveMemoryWarning];

   // zrzeczenie si wasnoci wszelkich buforowanych danych, obrazw itd., ktre nie s obecnie uywane
}

- (void)viewDidUnload
{
   [super viewDidUnload];

   // zrzeczenie si wasnoci wszelkich danych, ktre mona odtworzy w metodzie viewDidLoad lub na danie,
   // np. self.myOutlet = nil;
}

- (void)dealloc
{
   [super dealloc];
}

#pragma mark - Metody prywatne

- (NSInteger)fibonacci:(NSInteger)term
{
   if(term == 0)
   {
      return 0;
   } else if(term == 1) {
      return 1;
   } else {
      return [self fibonacci:term - 1] + [self fibonacci:term - 2];
   }
}

@end
