简体   繁体   English

Objective-C:未初始化表视图数据源的实例变量

[英]Objective-C: Instance variable for table view data source not being initialized

I'm initializing the data source like so: 我正在初始化数据源,如下所示:

@interface SelectWifiViewController() {
    NSArray *exampleNetworks;
}
@end

and: 和:

- (void) viewDidLoad: (BOOL) animated {
    [super viewDidLoad];

    exampleNetworks = [NSArray arrayWithObjects:@"network 1", @"network 2", "network 3", nil];
}

I'm using the data source here: 我在这里使用数据源:

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *tableCellIdentifier = @"wifiNetworkCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tableCellIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:tableCellIdentifier];
    }

    cell.textLabel.text = [NSString stringWithFormat:@"%@, Test", [exampleNetworks objectAtIndex:indexPath.row]];

    return cell;
}

which doesn't work; 这不起作用; "(null) Test" is printed on each cell. 在每个单元格上打印“(null)测试”。

Edit: 编辑:

Here is how I'm navigating to this view controller: 这是我如何导航到这个视图控制器:

- (void) navAction {
    UIStoryboard *selectWifiView = [UIStoryboard storyboardWithName:@"SelectWifiView" bundle:nil];
    UIViewController *vc = [selectWifiView instantiateViewControllerWithIdentifier:@"SelectWifiView"];
   [self.navigationController pushViewController:vc animated:YES];
}

There is no such method as: 没有这样的方法:

- (void)viewDidLoad:(BOOL) animated { ... }

You meant: 你的意思是:

- (void)viewDidLoad { ... }

Your current method is never going to be called, but if you eliminate that animated parameter, it should be. 您的当前方法永远不会被调用,但是如果您消除了该animated参数,它应该是。

I would suggest adding a breakpoint and/or NSLog statement whenever you suspect that a particular method is not getting called line you think it should be. 每当你怀疑某个特定方法没有得到你认为它应该被调用的行时,我建议添加一个断点和/或NSLog语句。 That will confirm whether it's called or not, and if not, you can then start to consider various reasons why it might not be getting to that line of code (in this case, because the method signature was incorrect). 这将确认是否被调用,如果没有,您可以开始考虑可能无法访问该行代码的各种原因(在这种情况下,因为方法签名不正确)。

Please correct viewDidLoad of iOS without animated as following: 请更正iOS的viewDidLoad,不要动画如下:

- (void)viewDidLoad {
   [super viewDidLoad];
   // Do any additional setup after loading the view.
}

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

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