在View执行加载后,IBOutlet UITableView是null [英] IBOutlet UITableView is null after View did load
问题描述
以下是基本代码(基于Xcode的Tabbed应用模板)
Here's the basic code (based on Xcode's Tabbed Applicaion Template)
ViewController.h
ViewController.h
@interface ViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
@property (nonatomic,retain) NSMutableArray *movies;
@property (nonatomic,retain) IBOutlet UITableView *tableView;
ViewController.m
ViewController.m
@implementation ViewController
@synthesize movies,tableView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(@"Watchlist", @"Watchlist");
self.tabBarItem.image = [UIImage imageNamed:@"watchlist"];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"tableView = %@", tableView);
}
输出
tableView = (null)
TableView连接到文件的所有者在IB中,类被设置为ViewController
The TableView is connected to File's owner in IB with class is set to ViewController
我真的不明白为什么tableView是null。
我不是一个完整的新手Cocoa(但对于iPhone SDK),我创建了一个基于单个视图的应用程序与TableView dataSource,看看我是否缺少的东西。
I really don't get why the tableView is null. I'm not a complete newbie to Cocoa (but to the iPhone SDK), I created a Single View based Application with a TableView dataSource to see if I was missing something. I got it working in under a minute.
推荐答案
在界面生成器中,右键单击文件所有者
,并确保创建以下连接:
In interface builder right click File's Owner
and ensure that the following connections are made:
Outlets
tableView - Table View
Referencing Outlets
dateSource - Table View
delegate - Table View
我怀疑你可能没有进行第一次连接?
I suspect you may have not made the first connection?
这篇关于在View执行加载后,IBOutlet UITableView是null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!