在viewController中重新加载tableView

时间:2014-03-26 18:12:10

标签: ios objective-c uitableview

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

以下是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;
}

我是否缺少一些特殊的命令来调用一个不属于TableViewCOntroller的视图控制器中的tableView?

3 个答案:

答案 0 :(得分:2)

您需要制作IBOutlet tableView并致电reloadData

答案 1 :(得分:0)

这取决于您宣布UITableView

的方式

如果是属性(@property (nonatomic, strong) UITableView *myTableView),则为[self.myTableView reloadData]。如果您将其声明为实例变量(UITableView *_myTableView),则它将为[_myTableView reloadData]

答案 2 :(得分:0)

您必须定义tableview数据源并委托为自己..如table.datasource=self, 和table.delegate=self .....你可以在viewdidload中执行....但是如果你已经在某处下载了数据,那么你可以在你下载的地方完成它并在那里重新加载表。请将代理和数据源分配到表中,并在下载数据后重新加载tableview ....请创建(@property (nonatomic, strong) UITableView *table)之类的属性,并在重新加载时使用self ...

相关问题