-4

Not sure where I went wrong. My understanding is that importing UIKit will enable use of the numberOfSectionsInTableView method... Any help is appreciated.

//HEADER

#import <UIKit/UIKit.h>

@interface MainScrollingTableVC : UITableViewController <UITableViewDelegate, UITableViewDataSource> {
    int selectedIndex;
    NSMutableArray *titleArray;
    NSArray *subtitleArray;
    NSArray *textArray;
}

@end

//IMPLEMENTATION

#import "MainScrollingTableVC.h"
#import "MainExpandingCellTableViewCell.h"

@interface MainScrollingTableVC ()

@property (strong, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation MainScrollingTableVC

- (void)viewDidLoad {
    [super viewDidLoad];

    self.tableView.delegate = self;
    self.tableView.dataSource = self;

    //index = -1 means no cell is expanded or should expand
    selectedIndex = -1;

    titleArray = [[NSMutableArray alloc] init];
    NSString *string;

    //create consecutive array of 8 numbers. 1...2...etc...
    for(int ii = 1; ii <= 8; ii++) {
        string = [[NSString alloc] initWithFormat:@"Row %i", ii];
        [titleArray addObject:string];

    }

    subtitleArray = [[NSArray alloc] initWithObjects:@"First row", @"Second row", @"Third row", @"Fourth row", @"Fifth row", @"Sixth row", @"Seventh row", @"Eigth row", nil];

    textArray = [[NSArray alloc] initWithObjects:@"Apple", @"Orange", @"Grape", @"Banana", @"Kiwi", @"Blueberry", @"Apricot", @"Lemon", nil];

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
        return 1;
    }

    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        return titleArray.count;
    }

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        static NSString *cellIdentifier = @"MainExpandingCell";
        MainExpandingCell *cell = (MainExpandingCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        if(cell == nil) {
            NSArray *nib  = [[NSBundle mainBundle] loadNibNamed:@"MainExpandingCell" owner:self options:nil];
            cell = [nib objectAtIndex:0];
        }
        if(selectedIndex == indexPath.row) {
            //Do expanded cell stuff
        } else {
            //Do closed cell stuff
        }

        cell.titleLabel.text  = [titleArray objectAtIndex:indexPath.row];
        cell.timeLabel.text = [subtitleArray objectAtIndex: indexPath.row]; //CHECK VARS
        cell.textLabel.text =  [textArray objectAtIndex:indexPath.row];
        int etaLabel = (indexPath.row + 1) * 25;
        cell.etaLabel.text =  [NSString stringWithFormat:@"%i", eta]
        cell.clipsToBounds = YES;

        return cell;
    }

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
Bryan Chen
  • 45,816
  • 18
  • 112
  • 143
Purp
  • 1
  • 1

1 Answers1

1

You are declaring your methods inside the viewDidLoad method. Objective-C doesn't support method nesting. Fix your whole code with its formatting and add the missing } accordingly.

Andy Ibanez
  • 12,104
  • 9
  • 65
  • 100