在 viewController 中重新加载 tableView [英] Reload a tableView inside viewController

查看:31
本文介绍了在 viewController 中重新加载 tableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的故事板上设置了一个视图控制器,并且在这个视图控制器中插入了一个 tableView.我想在 viewDidLoad 上做一个 [self.tableView reloadData];,但它说没有找到属性 tableView.

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.

以下是 viewcontroller.m 文件中 tableView 的代码:

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;
}

我是否缺少一些特殊命令来调用视图控制器中的 tableView,而该控制器不是 TableViewCONtroller?

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

推荐答案

你需要制作一个 tableViewIBOutlet 并调用 reloadData

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

这篇关于在 viewController 中重新加载 tableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆