lenga hao lenga hao - 5 months ago 32
iOS Question

UIButton performSelector:withObject:withObject: not making call

here is my code.

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(110, 270, 100, 40);
button.backgroundColor = [UIColor grayColor];
[button setTitle:@"next" forState:UIControlStateNormal];
[self.view addSubview:button];


I want to set button title color through this method
but it doesn't work!

[button performSelector:@selector(setTitleColor:forState:)
withObject:[UIColor blackColor]
withObject:@(UIControlStateNormal)];


Do somebody know why it doesn't work???

Answer

Why don't you simply use [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

And in your case

[button performSelector:@selector(setTitleColor:forState:)
             withObject:[UIColor redColor]
             withObject:UIControlStateNormal];

Remove @() for UIControlStateNormal.