0

I have a viewcontroller set up on my storyboard, and I have inserted a tableView inside this view controller. I want to do a [self.tableView reloadData]; on viewDidLoad, but it says the property tableView isn't found.

Here is what the code for my tableView in the viewcontroller.m file looks like:

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

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section     {
    return @"Shared with";
}

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

- (sharedUsersTable *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"sharedUser";

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

    NSDictionary *key = [activeUsers objectAtIndex:indexPath.row];
    NSString *name = [key objectForKey:@"shared_user_name"];
    NSString *email = [key objectForKey:@"email"];

    cell.textLabel.text = [NSString stringWithFormat:@"%@", name];
    cell.detailTextLabel.text = [NSString stringWithFormat:@"%@", email];

    return cell;
}

Am I missing some special command to call a tableView inside a view controller which isn't a TableViewCOntroller?

David
  • 3,285
  • 1
  • 37
  • 54
Angad
  • 84
  • 1
  • 9

3 Answers3

2

You need to make a IBOutlet of tableView and call reloadData on that.

Shubhank
  • 21,721
  • 8
  • 65
  • 83
  • Thanks, that should work. However, the view isn't loading the data. If my tableview is called `sharedView` how should I modify the code above to have it render correctly? I assume right now, my code isn't defining the correct tableView. – Angad Mar 26 '14 at 18:23
  • 1
    you have to assign the delegate and datasource. use `tableView.datasource = self;` and `tableView.delegate = self;` – Shubhank Mar 26 '14 at 18:24
  • Where exactly do I define those? – Angad Mar 26 '14 at 18:25
0

This depends on how you declared your UITableView.

If it is a property (@property (nonatomic, strong) UITableView *myTableView), it will be [self.myTableView reloadData]. If you declared it as just an instance variable (UITableView *_myTableView), it will be [_myTableView reloadData].

Dima
  • 23,484
  • 6
  • 56
  • 83
0

you'll have to define tableview datasource and delegate as self.. like table.datasource=self, and table.delegate=self.....you can do it in viewdidload....but if you have downloaded the data somewhere, then you can do it in that place where you have downloaded and reload the table there. please assign the delegate and datasource to the table and reload the tableview after you have downloaded the data....and please make a property like(@property (nonatomic, strong) UITableView *table)and use self when you do the reload...