为什么我的 UITableView 没有被设置?
我在 viewDidLoad 方法中使用调试器进行了检查,tracerTableView 是 0x0,我认为这意味着它为零。我不明白。我应该说是的,我已经检查了我的 nib 文件,是的,所有连接都是正确的。这是头文件和 .m 的请求。
.h 文件
@interface TrackerListController : UITableViewController <AddPackageDelegate>{
// The mutable (modifiable) dictionary days holds all the data for the days tab
NSMutableArray *trackerList;
UITableView *tracerTableView;
}
@property (nonatomic, retain) NSMutableArray *trackerList;
@property (nonatomic, retain) IBOutlet UITableView. *tracerTableView;
//The addPackage: method is invoked when the user taps the addbutton created at runtime.
-(void) addPackage : (id) sender;
@end
.m 文件
@implementation TrackerListController
@synthesize trackerList, tracerTableView;
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"Package Tracker";
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addPackage:)];
// Set up the Add custom button on the right of the navigation bar
self.navigationItem.rightBarButtonItem = addButton;
[addButton release];
// Release the addButton from memory since it is no longer needed
}
I checked using the debbuger in the viewDidLoad method and tracerTableView is 0x0 which i assume means it is nil. I don't understand. I should go ahaed say yes I have already checked my nib file and yes all the connections are correct. Here is the header file and the begging of the .m.
.h file
@interface TrackerListController : UITableViewController <AddPackageDelegate>{
// The mutable (modifiable) dictionary days holds all the data for the days tab
NSMutableArray *trackerList;
UITableView *tracerTableView;
}
@property (nonatomic, retain) NSMutableArray *trackerList;
@property (nonatomic, retain) IBOutlet UITableView. *tracerTableView;
//The addPackage: method is invoked when the user taps the addbutton created at runtime.
-(void) addPackage : (id) sender;
@end
.m file
@implementation TrackerListController
@synthesize trackerList, tracerTableView;
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"Package Tracker";
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addPackage:)];
// Set up the Add custom button on the right of the navigation bar
self.navigationItem.rightBarButtonItem = addButton;
[addButton release];
// Release the addButton from memory since it is no longer needed
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该表已经是一个 IBOutlet。您可以在 2 个位置指定它们,首先在声明中或在 @property 行上。所以看起来没问题。
tableview 连接到 .h 文件中的 tracerTableView 属性,并且您可以正确地合成它们。
如何加载 ViewController。你用 NibName 初始化它吗?您也可以发布该代码吗?因为只是将其初始化为:
当您想使用笔尖时似乎不起作用。尝试使用这个代替:
The table is already an IBOutlet. You can specify those on 2 places, first in the declaration or on the @property line. So that seems ok.
The tableview is connected to the tracerTableView property in the .h file and you synthesize them correctly.
How do you load the ViewController. Do you init it with NibName? Could you maybe post that code too? Because just initializing it as:
Doesnt seem to work when you want to use a nib. Try using this instead:
也许你有一个错字。以下行:
应该是:
为了清楚起见,在头文件中,我将声明表视图为 Interface Builder 出口:
执行此操作后,为了仔细检查,我还要确保文件的所有者(视图控制器)在 XIB 中从文件所有者连接到表视图。
Perhaps you have a typo. The following line:
should be:
To be clear, in the header file, I would declare the table view to be an Interface Builder outlet:
After doing this, to double-check, I would also make sure the File's Owner (the view controller) in your XIB is wired up from the File's Owner to the Table View.