@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIButton *button;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
int tag = [self.button tag];
UIButton *btn = (UIButton *) [self.view viewWithTag:1001];
btn.titleLabel.text = @"hello world";
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
上面是代码,现在出现的问题是: int tag = [self.button tag];返回了tag的值,我设置的是1001。
但是 UIButton *btn = (UIButton *) [self.view viewWithTag:1001];返回的却是nil。
我搜了下google,也没看到有人解决了这个问题。 http://84.15.64.35/#newwindow=1&q=self.view+viewWithTag+return+nil
所以,在这里请教下大家了。
for (UIView *v in self.view.subviews) { NSLog("%d", (int)v.tag; }
看看到底有没有 1001这个...