简体   繁体   English

为什么我会为此出错?

[英]Why am I getting an error for this?

Why am I getting these errors? 为什么会出现这些错误? alt text http://img39.imageshack.us/img39/2203/help.tif 替代文字http://img39.imageshack.us/img39/2203/help.tif

It says: 它说:

Error: Request for member "jokeTableView" in something not a struction or union 错误:请求成员“ jokeTableView”的操作不是指令或联合

What does that mean? 这意味着什么? And why is it breaking. 以及为什么会破裂。 I tried reading about initWithStyle but I just could catch up on it 我尝试阅读有关initWithStyle的内容,但我可以赶上它

Here is my .h file: 这是我的.h文件:

#import <UIKit/UIKit.h>


 @interface TableViewController : UITableViewController {

NSMutableArray *jokes;
IBOutlet UITableView *jokeTableView; 


 } 

 @property (nonatomic, retain) NSMutableArray *jokes;

 @end

Thanks! 谢谢!

Your object (TableViewController) has no property named jokeTableView. 您的对象(TableViewController)没有名为jokeTableView的属性。

In order to access jokeTableView with the special dot operator, it needs to be a property. 为了使用特殊的点运算符访问jokeTableView,它必须是一个属性。 Otherwise you have to access it using Key-Value-Coding compliant methods or directly using the -> operator (or just use it as an ivar and no reference to self): 否则,您必须使用兼容键值编码的方法或直接使用->运算符(或仅将其用作ivar且不引用self)来访问它:

jokeTableView.delegate = self;

or 要么

self->jokeTableView.delegate = self;

or 要么

[self jokeTableView].delegate = self;

or 要么

@property (retain) UITableView *jokeTableView;
// later...
self.jokeTableView.delegate = self;

Also note, however, that you are setting an outlet in the initializer and this won't work. 另请注意,但是,您正在初始化器中设置插座,这将不起作用。 You'll have to set this in the -[TableViewController awakeFromNib] method since self->jokeTableView will be nil when the initializer is actually called (which happens in IB prior to serializing the object into the nib file). 您必须在-[TableViewController awakeFromNib]方法中进行设置,因为当实际调用初始化程序时,self-> jokeTableView将为nil(在IB中发生在将对象序列化到nib文件之前)。

Since you are doing this at init time, the outlets should be NULL, so this initialization shouldn't do anything. 由于您是在初始化时执行此操作的,因此出口应为NULL,因此此初始化不应执行任何操作。 This should be done at awakeFromNib time at the earliest. 最早应该在awakeFromNib时间执行此操作。

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

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