ios - 在 viewController 中重新加载一个 tableView

标签 ios objective-c uitableview

我在 Storyboard上设置了一个 View Controller ,并在该 View Controller 中插入了一个 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 的 View Controller 中调用 tableView?

最佳答案

您需要制作一个tableViewIBOutlet 并在其上调用reloadData

关于ios - 在 viewController 中重新加载一个 tableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22669606/

相关文章:

c# - Xamarin 如何根据默认设置以编程方式选择uitableview单元格

ios - 操作按钮未出现在通知 iOS 10 中

android - phonegap 从 url 下载图像并将其保存到应用程序安装文件夹

ios - 在iOS上将链接(图像URL或网站URL)发布为Instagram的标题

ios - 在 TodayExtension 中使用 MagicalRecord (CoreData)

objective-c - iOS 中的键盘快捷键?

ios - (Swift) 以编程方式在 UITableViewController 上方添加 UIView

iphone - 创建 NSMutableArray 的副本并仅在一个数组中编辑元素

ios - Objective C (iOS) 中的 VLA 可变长度数组,会发生什么?

ios - UITableView可以上下拖动,不允许Swipe Gesture?