我已经为几个按钮创建了一个 socket 集合,现在我需要更改按钮的背景,这是我的代码,但编译器给了我一个错误:
[outlet makeObjectsPerformSelector:@selector(setBackgroundImage:img forState:UIControlStateSelected)];
错误:
Expected ':'
如何解决?
编辑:
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 100, 50)];
imgView.image = [UIImage imageNamed:@"mask.png"];
[outlet makeObjectsPerformSelector:@selector(setBackgroundImage:)withObject:imgView];
[imgView release];
最佳答案
您不能将参数放入@selector(...)
。您需要使用 makeObjectsPerformSelector:withObject:
,例如你的代码应该类似
[EsOutlet makeObjectsPerformSelector:@selector(setBackgroundImage:) withObject:img];
我这么说是因为我认为没有一种方法可以为需要多个参数的选择器执行此操作。
关于iphone - 将背景图片添加到 Outlet Collection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9687140/