为什么我的 UITableView 没有被设置?

发布于 2024-08-30 16:05:17 字数 1375 浏览 4 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

末が日狂欢 2024-09-06 16:05:17

该表已经是一个 IBOutlet。您可以在 2 个位置指定它们,首先在声明中或在 @property 行上。所以看起来没问题。

tableview 连接到 .h 文件中的 tracerTableView 属性,并且您可以正确地合成它们。

如何加载 ViewController。你用 NibName 初始化它吗?您也可以发布该代码吗?因为只是将其初始化为:

TrackerListController* viewControl = [[TrackerListController alloc] init];

当您想使用笔尖时似乎不起作用。尝试使用这个代替:

TrackerListController* viewControl = [[TrackerListController alloc]
initWithNibName:@"trackerListController" bundle:nil];

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:

TrackerListController* viewControl = [[TrackerListController alloc] init];

Doesnt seem to work when you want to use a nib. Try using this instead:

TrackerListController* viewControl = [[TrackerListController alloc]
initWithNibName:@"trackerListController" bundle:nil];
爱,才寂寞 2024-09-06 16:05:17

也许你有一个错字。以下行:

@property (nonatomic, retain) IBOutlet UITableView. *tracerTableView;

应该是:

@property (nonatomic, retain) IBOutlet UITableView *tracerTableView;

为了清楚起见,在头文件中,我将声明表视图为 Interface Builder 出口:

IBOutlet UITableView *tracerTableView;

执行此操作后,为了仔细检查,我还要确保文件的所有者(视图控制器)在 XIB 中文件所有者连接到表视图。

Perhaps you have a typo. The following line:

@property (nonatomic, retain) IBOutlet UITableView. *tracerTableView;

should be:

@property (nonatomic, retain) IBOutlet UITableView *tracerTableView;

To be clear, in the header file, I would declare the table view to be an Interface Builder outlet:

IBOutlet UITableView *tracerTableView;

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文