Question

i my iphone app while assigning a string value to the table view its crashing, i have the following code in cellForRowAt index path method

while assigning a string value to the table view

NSMutableArray *arrTrimmedTblData=[[NSMutableArray alloc]init];
NSMutableString *strTrimmedTblData;
for(int intVar=0;intVar<[array count];intVar++)
{

    strTrimmedTblData = [NSMutableString stringWithFormat:@"%@",[array objectAtIndex:intVar]];
    [strTrimmedTblData replaceOccurrencesOfString:@"("  withString:@""  options:NSLiteralSearch range:NSMakeRange(0, [strTrimmedTblData length])];
    [strTrimmedTblData replaceOccurrencesOfString:@")"  withString:@""  options:NSLiteralSearch range:NSMakeRange(0, [strTrimmedTblData length])];
    [strTrimmedTblData replaceOccurrencesOfString:@" "  withString:@""  options:NSLiteralSearch range:NSMakeRange(0, [strTrimmedTblData length])];
    [strTrimmedTblData replaceOccurrencesOfString:@"\""  withString:@""  options:NSLiteralSearch range:NSMakeRange(0, [strTrimmedTblData length])];
    [strTrimmedTblData replaceOccurrencesOfString:@"\n"  withString:@""  options:NSLiteralSearch range:NSMakeRange(0, [strTrimmedTblData length])];
    [arrTrimmedTblData addObject:strTrimmedTblData];
}

NSLog(@"arrTrimmedTblData:%@",arrTrimmedTblData);
NSLog(@"arrTrimmedTblData:%@",[arrTrimmedTblData objectAtIndex:0]);
NSString *cellValue = [arrTrimmedTblData objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;

its crashing at this line cell.textLabel.text = cellValue;

crash log: variable cellValue is not a CFString

please any buddy do help me, thanx in advance

Was it helpful?

Solution

Have you allocated your cell with an instance of UITableViewCell ?

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reusableCell];

or

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reusableCell] autorelease];

OTHER TIPS

Try by changing

NSString *cellValue =[NSString stringWithFormat:@"%@",[arrTrimmedTblData objectAtIndex:indexPath.row]];

replaceOccurrencesOfString method return NSString object. So, you have to store return string in another string variable.

 NSString *cellValue = [[arrTrimmedTblData objectAtIndex:indexPath.row] retain];
 crashing Due To That Object is Not Available.
 I Hope It Will Work...

Cheers

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