iOS null Interface Builder 对象
大家好,
在这个方法中...
- (void)configureTableWithTitle:(NSString *)theTitleText about:(NSString *)theAboutText
{
debug(@"configuring with headerText: %@", theTitleText);
debug(@"headerView description: %@", [headerView description]);
debug(@"headerText description: %@", [headerText description]);
CGPoint titleOrigin = headerText.frame.origin;
CGSize titleSize = headerText.frame.size;
[headerText setText:theTitleText];
debug(@"headerText: %@", [headerText text]);
CGSize newTitleSize = [theTitleText sizeWithFont:[headerText font] constrainedToSize:CGSizeMake(titleSize.width, 9999)];
[headerText setFrame:CGRectMake(titleOrigin.x, titleOrigin.y, titleSize.width, newTitleSize.height)];
int titleDelta = newTitleSize.height - titleSize.height;
CGSize titleViewSize = headerView.frame.size;
[headerView setFrame:CGRectMake(0, 0, titleViewSize.width, titleViewSize.height + titleDelta)];
[[self tableView] setTableHeaderView:headerView];
debug(@"footerView description: %@", [footerView description]);
debug(@"footerText description: %@", [footerText description]);
CGPoint aboutOrigin = footerText.frame.origin;
CGSize aboutSize = footerText.frame.size;
[footerText setText:theAboutText];
CGSize newAboutSize = [theAboutText sizeWithFont:[footerText font] constrainedToSize:CGSizeMake(aboutSize.width, 9999)];
[footerText setFrame:CGRectMake(aboutOrigin.x, aboutOrigin.y, aboutSize.width, newAboutSize.height)];
int aboutDelta = newAboutSize.height - aboutSize.height;
CGSize aboutViewSize = footerView.frame.size;
[footerView setFrame:CGRectMake(0, 0, aboutViewSize.width, aboutViewSize.height + aboutDelta)];
[[self tableView] setTableFooterView:footerView];
}
作用于 footerView
的行footerText
可以工作,但那些作用于 headerView
& headerText
没有。这个屏幕截图展示了我如何在IB中连接事物。 debug
行(Marcus Zarra 的 NSLog 脚本)告诉我 headerView
& headerText
从一开始就为 null尝试设置文本后,headerText.text
为 null。在我的头文件中...
@interface MFProgramDetailView : UITableViewController <UITableViewDelegate>
{
UIView *headerView;
UIView *footerView;
UILabel *headerText;
UILabel *footerText;
UITableView *detailTable;
}
@property (nonatomic, retain) IBOutlet UIView *headerView;
@property (nonatomic, retain) IBOutlet UIView *footerView;
@property (nonatomic, retain) IBOutlet UILabel *headerText;
@property (nonatomic, retain) IBOutlet UILabel *footerText;
@property (nonatomic, retain) IBOutlet UITableView *detailTable;
我正在为这个文件撕扯我的头发。我已经检查过&重新检查并没有看到任何不合适的地方,我已经使用类似的方法将它与另一个类进行了多次比较(但在标题中需要处理的项目)&看不出有什么不同。
谁能提供任何线索来说明我是如何犯错的?鉴于这是我已经做过几次的事情,熟悉会导致盲目。
干杯& TIA, 佩德罗
G'day Folks
In this method...
- (void)configureTableWithTitle:(NSString *)theTitleText about:(NSString *)theAboutText
{
debug(@"configuring with headerText: %@", theTitleText);
debug(@"headerView description: %@", [headerView description]);
debug(@"headerText description: %@", [headerText description]);
CGPoint titleOrigin = headerText.frame.origin;
CGSize titleSize = headerText.frame.size;
[headerText setText:theTitleText];
debug(@"headerText: %@", [headerText text]);
CGSize newTitleSize = [theTitleText sizeWithFont:[headerText font] constrainedToSize:CGSizeMake(titleSize.width, 9999)];
[headerText setFrame:CGRectMake(titleOrigin.x, titleOrigin.y, titleSize.width, newTitleSize.height)];
int titleDelta = newTitleSize.height - titleSize.height;
CGSize titleViewSize = headerView.frame.size;
[headerView setFrame:CGRectMake(0, 0, titleViewSize.width, titleViewSize.height + titleDelta)];
[[self tableView] setTableHeaderView:headerView];
debug(@"footerView description: %@", [footerView description]);
debug(@"footerText description: %@", [footerText description]);
CGPoint aboutOrigin = footerText.frame.origin;
CGSize aboutSize = footerText.frame.size;
[footerText setText:theAboutText];
CGSize newAboutSize = [theAboutText sizeWithFont:[footerText font] constrainedToSize:CGSizeMake(aboutSize.width, 9999)];
[footerText setFrame:CGRectMake(aboutOrigin.x, aboutOrigin.y, aboutSize.width, newAboutSize.height)];
int aboutDelta = newAboutSize.height - aboutSize.height;
CGSize aboutViewSize = footerView.frame.size;
[footerView setFrame:CGRectMake(0, 0, aboutViewSize.width, aboutViewSize.height + aboutDelta)];
[[self tableView] setTableFooterView:footerView];
}
the lines that act on footerView
& footerText
work but those that act on headerView
& headerText
don't. This screen shot shows how I have things hooked up in IB. The debug
lines (Marcus Zarra's NSLog script) tell me that headerView
& headerText
are null from the beginning & that headerText.text
is null after attempting to set the text. In the eader file I have...
@interface MFProgramDetailView : UITableViewController <UITableViewDelegate>
{
UIView *headerView;
UIView *footerView;
UILabel *headerText;
UILabel *footerText;
UITableView *detailTable;
}
@property (nonatomic, retain) IBOutlet UIView *headerView;
@property (nonatomic, retain) IBOutlet UIView *footerView;
@property (nonatomic, retain) IBOutlet UILabel *headerText;
@property (nonatomic, retain) IBOutlet UILabel *footerText;
@property (nonatomic, retain) IBOutlet UITableView *detailTable;
I'm tearing my heair out over this one. I've checked & re-checked & fail to see anything out of place, I've compared it multiple times with another class using a similar method (but with items to juggle in the header) & can't see a difference.
Can anyone offer any clues as to how I'm getting this wrong? Given this is something I've done a few times p'aps familiarity has bred blindness.
Cheers & TIA,
Pedro
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在什么方法中调用 -(void)configureTableWithTitle: about: 方法?
您确定它在 viewDidLoad: 之后吗?
In what method do you call your -(void)configureTableWithTitle: about: method?
Are you sure, that it's after viewDidLoad: ?