I have a ViewController
named QuickLookView and I need to implement a table view into it. I have declared the tableview in my header file:
@interface QuickLookView : UIViewController <UITableViewDelegate, UITableViewDataSource>
...
@property (weak, nonatomic) IBOutlet UITableView *medTableView;
@end
In the QuicklookView.m
I synthesized medTableView and added the standard UITableView
methods:
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSMutableArray * timeline = [gCore getDosageContainer];
return [timeline count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath* )indexPath
{
static NSString *CellIdentifier = @"medicineCell";
UITableViewCell *cell = [medTableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
NSMutableArray * timeline = [gCore getDosageContainer];
GuardianPatientDosageTimeline * d;
d = (GuardianPatientDosageTimeline *) [timeline objectAtIndex: indexPath.row];
NSString *MedTimeLine = [NSString stringWithFormat:@"%.02f %@ of %@",d->amount,d->units,d- >name];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.font = [UIFont fontWithName:@"ProximaNova-Regular" size:15];
cell.textLabel.text = MedTimeLine;//"toDoItem.itemName;
return cell;
}
This is how my delegate and datasource is hooked up:
Outlets
datasource------------------->QuickLook View
delegate--------------------->QuickLook View
Referencing Outlets
medTableView---------------->QuickLook View
(I would have posted a picture, but my reputation is not big enough...)
But I am still getting an error after trying a multitude of things. From replacing my return [timeline count];
with a normal integer to linking things to who knows what. All the data in "timeline" and "gCore" is used outside of this file, so I know there is data in there.
Here is the error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView tableView:numberOfRowsInSection:]: