【发布时间】:2012-11-08 09:23:50
【问题描述】:
我在情节提要中创建了一个UILabel。
my.h 文件
@interface EditAndControll : UIViewController
@property (strong, nonatomic) id detailItem;
@property (strong, nonatomic) IBOutlet UILabel *deviceDetailLabel;
- (void)configureView;
@end
我的.m 文件
@implementation EditAndControll
@synthesize detailItem = _detailItem;
@synthesize deviceDetailLabel = _deviceDetailLabel;
- (void)setDetailItem:(id)newDetailItem
{
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
// Update the view.
[self configureView];
}
}
- (void)configureView
{
if (self.detailItem)
{
DeviceCoreInfo *detailDevice = [DeviceCoreInfo alloc];
detailDevice = self.detailItem;
_deviceDetailLabel.text = detailDevice.deviceIP;
self.deviceDetailLabel.text=detailDevice.deviceIP;
NSLog(@"Device Label %@",_deviceDetailLabel);
NSLog(@"self Device LaBel %@", self.deviceDetailLabel);
}
}
NSLog 告诉我:
Device Label (null)
self Device LaBel (null)
我从主视图调用的所有内容:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSManagedObject *selectedObject = [[self fetchedResultsController] objectAtIndexPath:indexPath];
[[segue destinationViewController] setDetailItem:selectedObject];
}
}
我做错了什么?请帮忙!
【问题讨论】:
-
detailDevice 的 NSLog 是什么意思?
-
你从哪里调用 [self configureView]?
-
另外,UILabel IBOutlet 的属性应该是(非原子的,弱的)。哦,去掉 synthesize 调用,如果你只是使用标准调用,它们就不再需要了。
-
DetailDevice 没问题,从 EditAndControll 方法调用 configureView
-
你为什么写
DeviceCoreInfo *detailDevice = [DeviceCoreInfo alloc];?你正在泄漏内存。
标签: iphone objective-c ios ios5 storyboard