简体   繁体   English

在viewController中重新加载tableView

[英]Reload a tableView inside viewController

I have a viewcontroller set up on my storyboard, and I have inserted a tableView inside this view controller. 我在我的故事板上设置了一个viewcontroller,我在这个视图控制器中插入了一个tableView。 I want to do a [self.tableView reloadData]; 我想做一个[self.tableView reloadData]; on viewDidLoad, but it says the property tableView isn't found. 在viewDidLoad上,但它说找不到属性tableView。

Here is what the code for my tableView in the viewcontroller.m file looks like: 以下是viewcontroller.m文件中tableView的代码如下所示:

- (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? 我是否缺少一些特殊的命令来调用一个不是TableViewCOntroller的视图控制器中的tableView?

你需要创建一个tableViewIBOutlet并在其上调用reloadData

This depends on how you declared your UITableView . 这取决于您如何声明UITableView

If it is a property ( @property (nonatomic, strong) UITableView *myTableView ), it will be [self.myTableView reloadData] . 如果它是一个属性( @property (nonatomic, strong) UITableView *myTableView [self.myTableView reloadData] ),它将是[self.myTableView reloadData] If you declared it as just an instance variable ( UITableView *_myTableView ), it will be [_myTableView reloadData] . 如果您将其声明为实例变量( UITableView *_myTableView ),则它将是[_myTableView reloadData]

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. 你必须定义tableview数据源并委托为自己..如table.datasource=selftable.delegate=self .....你可以在viewdidload中执行....但是如果你已经在某处下载了数据,然后你可以在你下载的地方完成它并在那里重新加载表格。 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... 请将委托和数据源分配给表,并在下载数据后重新加载tableview ....并且请创建类似(@property (nonatomic, strong) UITableView *table)的属性(@property (nonatomic, strong) UITableView *table)并在重新加载时使用self。 ..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM