I try to refresh background image of an uibutton, this is the code for create button
- (void) disegnaAnteprime {
int x = 2;
int y = 2;
int i = 0;
scrollView.contentSize = CGSizeMake(self.view.frame.size.width, 10*103);
for (i=0; i < arrayProgetti.count;i++) {
NSNumber *indice = [NSNumber numberWithInt:i];
elemento = [arrayProgetti objectAtIndex:i];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setTitle:[elemento objectForKey:@"Titolo"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(openPdf:) forControlEvents:UIControlEventTouchUpInside];
[button setContentVerticalAlignment:UIControlContentVerticalAlignmentBottom];
button.tag = i;
NSURL *indirizzoImmagine = [NSURL URLWithString:[elemento objectForKey:@"IndirizzoIcona"]];
NSLog(@"Indice i: %d",i);
NSData *imageData = [cache cachedResponseDataForURL:indirizzoImmagine];
if (imageData==nil) {
[self loadURL:indirizzoImmagine idElementoBottone:indice tipoRichiesta:NO];
}
else {
[button setImage:[UIImage imageWithData:imageData] forState:UIControlStateNormal];
}
button.frame = CGRectMake(30, y, 190, 190);
y = y + 192;
[self.scrollView addSubview:button];
}
}
while this is the code that I use for refresh button image
- (void)requestFinished:(ASIHTTPRequest *)request
{
int tag = [[request.userInfo objectForKey:@"TagBottone"] intValue];
NSLog(@"Tag: %d",tag);
[(UIButton*)[self.scrollView viewWithTag:tag] setTitle:@"hello" forState:UIControlStateNormal];
}
but I get this error
[UIScrollView setTitle:forState:]: unrecognized selector sent to instance 0x8179eb0
2012-03-28 23:54:40.477 iVision[2269:15b03] * Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[UIScrollView setTitle:forState:]: unrecognized selector sent to instance 0x8179eb0’
* First throw call stack:
(0x1c5f052 0x37f3d0a 0x1c60ced 0x1bc5f00 0x1bc5ce2 0xd574 0x1c60e72 0x37d0b 0x1c60e72 0x12879ef 0x1c3397f 0x1b96b73 0x1b96454 0x1b95db4 0x1b95ccb 0x1df1879 0x1df193e 0x96fa9b 0x3560 0x2d85)
where is the mistake?
edit:for now I try only to change titletex.
thank you!
This states that you are trying to use setTitle:forState: in a scrollView rather than a UIButton. Have you tried separating the code:
You can also check if your casting is succeeding:
It all indicates that the result of viewWithTag is not a UIButton. UIScrollView has some subviews itself. I would start your tags with a value of 100 and then, just add 100 to the result of the request. This avoids conflicts with existing subviews.
Hope it helps.