【发布时间】:2016-10-24 01:44:34
【问题描述】:
我想从 viewController 发送一些东西到另一个我使用 NSNotification 的 viewController。
我在第一个 vc 中定义了按钮,在第二个 vc 中定义了标签。当我点击按钮时,我想查看标签上的点击次数,但它有问题。我收到在“UIView”类型的对象上找不到“属性”文本错误。
我该如何解决这个问题?
---firstVC.h---
import <UIKit/UIKit.h>
@interface FirstViewController : UIViewController
- (IBAction)btnTap:(id)sender;
@end
---firstVC.m---
import "FirstViewController.h"
@interface FirstViewController ()
@end
@implementation FirstViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (IBAction)btnTap:(id)sender {
[[NSNotificationCenter defaultCenter] postNotificationName:@"not" object:nil];
}
@end
---secondVC.h---
import <UIKit/UIKit.h>
@interface SecondViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIView *lbl;
@property int number;
@end
---secondVC.m---
import "SecondViewController.h"
@interface SecondViewController ()
@end
@implementation SecondViewController
@synthesize number,lbl;
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationMethod:) name:@"not" object:nil];
number=0;
}
-(void) notificationMethod :(NSNotificationCenter *) notification{
number++;
lbl.text = [NSString stringWithFormat: @"%d",number];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
【问题讨论】:
-
什么是
lbl?你能出示lbl的声明吗? -
看起来您已将
lbl声明为UIView。 -
lbl 只是 secondViewController @Ronak Chaniyara 中标签的名称
-
显示您声明它的 secondViewController 的
.h文件的代码。 -
我写了所有有问题的代码,我写了'lbl',当我写'lbl'时。我看不到“文本”,我认为文本必须在“lbl”之后。
标签: objective-c