【问题标题】:UILabel troubleUIL标签问题
【发布时间】: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


【解决方案1】:

Hey Check Form 你在哪里调用这个- (void)configureView 方法。

你需要将该方法调用为

- (void)viewDidLoad {
   // configureView method From here.
}

谢谢

【讨论】:

  • 七个小时的编码让我瞎了眼!你会好的!!viewDidLoad 调用的每个人都是正确的!!!非常感谢!
猜你喜欢
  • 2012-05-04
  • 2012-03-12
  • 2011-03-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-10
相关资源
最近更新 更多