Question

I am programmatically adding a UIButton to a datePicker:

 //today button
 CGRect todayButtonFrame = CGRectMake(180.0, 200.0, 40.0, 40.0);
 UIButton *todayButtonDatePicker = [[UIButton alloc]initWithFrame:todayButtonFrame];
 [todayButtonDatePicker addTarget:self action:@selector(myCustomFunction:) forControlEvents:UIControlEventTouchUpInside];
 [todayButtonDatePicker setBackgroundImage:[UIImage imageNamed:@"today.png"] forState:UIControlStateNormal];

[self.view addSubview: todayButtonDatePicker];

However, the compiler is giving me a warning:

Local declaration of 'todayButtonDatePicker' hides instance variable
Was it helpful?

Solution

If you want to keep the UIButton as a property, do this:

 //today button
 CGRect todayButtonFrame = CGRectMake(180.0, 200.0, 40.0, 40.0);
 self.todayButtonDatePicker = [[UIButton alloc]initWithFrame:todayButtonFrame];
 [self.todayButtonDatePicker addTarget:self action:@selector(myCustomFunction:)forControlEvents:UIControlEventTouchUpInside];
 [self.todayButtonDatePicker setBackgroundImage:[UIImage imageNamed:@"today.png"] forState:UIControlStateNormal];

 [self.view addSubview: self.todayButtonDatePicker];

Alternatively you can remove the property and just use a local variable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top