0

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:]:

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
momodude22
  • 112
  • 1
  • 10
  • Have you tried placing a breakpoint on "NSMutableArray * timeline = [gCore getDosageContainer];" to see what the actual count is? Also it should be an NSArray as you are not modifying it. Actually, scratch that - you just need to do: "return [[gCore getDosageContainer] count];" – Nick Jun 19 '14 at 19:54
  • @Nick I just tried the "return [[gCore getDosageContainer] count];" and I got the same error message. I even get the error message when i change that section not "return 1;" for example. Which leads me to believe I have a problem with my delegation/datasourcing, I just don't know what. – momodude22 Jun 19 '14 at 20:17

3 Answers3

0

In the Attributes Inspector for your table view, does it look something like this:

enter image description here

Nick
  • 939
  • 1
  • 12
  • 19
  • Yes, that is exactly what mine looks like, just with the appropriate local names – momodude22 Jun 19 '14 at 21:00
  • Is there more to the error you get, such as "unrecognized selector sent to instance". If so, I would suggest you have a look at http://stackoverflow.com/questions/17350280/nsinvalidargumentexception-reason-nscfstring-isdecompressing-unrecog and try some of the suggestions (exception breakpoint/turn in zombies) – Nick Jun 19 '14 at 21:18
0

Try to remove delegate and datasource outlets from interface builder, and set it programmatically

 -(void)viewDidLoad
{
    //..
    self.tableView.delegate   = self;
    self.tableView.dataSource = self;
}

It seems that you connected that outlets to your view instead of view controller.

arturdev
  • 10,884
  • 2
  • 39
  • 67
0

Turns out I accidentally placed two UITableView's on top of each other in the rush of the layout. This explains why the numberOfRowsInSection was not being called - as it was referring to the secondary UITableView hidden under my main one. All of the the other methods above work for connecting a UITableView to a UIViewController, my problem specifically was just user error.

momodude22
  • 112
  • 1
  • 10