Im going crazy trying to debug a problem, where I get an exception
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString setText:]: unrecognized selector sent to instance 0x5799c90'
the code that is throwing it is:
- (void)request:(ASIHTTPRequest *)request didReceiveBytes:(long long)bytes
{
for(int index=0;index<[pendingDownloadsArray count];index++)
{
if ([request isE开发者_StackOverflow中文版qual:[[pendingDownloadsArray objectAtIndex:index]objectForKey:@"request"]])
{
NSNumber *x = [[pendingDownloadsArray objectAtIndex:index] objectForKey:@"completed"];
float newCompleted = [x floatValue]+(float)bytes;
// x+=(float)bytes;
NSLog(@"Completed: %fKb",newCompleted/1024);
x = [NSNumber numberWithFloat:newCompleted];
[[pendingDownloadsArray objectAtIndex:index] setObject:x forKey:@"completed"];
float progress = newCompleted / (float)request.contentLength;
//Dont try to get cell if the table is showing something else.
if(self.selectedSegment ==0)
{
DownloadsCustomCell *cell =(DownloadsCustomCell*) [downloadsTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0]];
[cell.downloadProgressView setProgress:progress];
NSString *progressLabelText = [NSString stringWithFormat:@"%.2f percent (%.2fKb / %.2fKb)",progress*100,
newCompleted/1024,((float)request.contentLength/1024)];
NSLog(@"%@",progressLabelText);
UILabel *label = cell.downloadProgressLabel;
label.text = progressLabelText;
}
}
}
}
its throwing the exception on the last line. (i did not have the unnecessary 'label' at first... so its existence is a mark of how confused i am. either problem is something I didnt know, or im doing something incredibly stupid that I am not able to spot. Can you please help me assign that NSString to that UILabel? (PS: i checked, downloadsProgressLabel IS A UILABEL.)
Option 1 - The problem is that the label was deallocated. cell.downloadProgressLabel points to bad memory, which happens to be a string sometimes, you should get different errors when executing that code.
Option 2 - you're creating downloadProgressLabel as a string instead of a uilabel, or you're doing cell.downloadProgressLabel = [some string object]; somewhere in the code by mistake, although that should give a warning :)
I have doubt over below line, Check the type of downloadProgressLabel
, it could be NSString
declared in your cell class,
Use below code.
if ([cell.downloadProgressLabel isKindOfClass:[UILabel class]])
{
UILabel *label = cell.downloadProgressLabel;
label.text = progressLabelText;
}
精彩评论