This is my code to display an attributed string in a UITextView
NSMutableAttributedString *recipeString =[[NSMutableAttributedString alloc]init];
[recipeString appendAttributedString:string1];
[recipeString appendAttributedString:string2];
[array addObject:recipeString];
This code is inside a for loop. string1 and string2 are NSMutableAttributedStrings.
After that:
self.textView.text = [array objectAtIndex:self.appDelegate.selectedCell];
The text view is an IBOutlet.
It crashes with this exception:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteAttributedString _isCString]: unrecognized selector sent to instance 0x8e866f0'
Any ideas on how to fix this crash?
I had to use the attributedText property of UITextView:
self.textView.attributedText = [array objectAtIndex:self.appDelegate.selectedCell];
For future users:
-[NSConcreteAttributedString mutableString]: unrecognized selector sent to instance
this may also be caused by if in the above instance string1 or string2 is nil
Related
when i enter any character or number with keyboard.the app crash with this info
"Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[NSNull length]: unrecognized
selector sent to instance 0x103b5daf0'".
And every textfield that used in the app has this problem.The textfield is in a storybord-based appliction.this is the textfield delegate i overwrite and this is the exception throw call stack
The problem is probably that you somewhere set the textField's text property to NSNull (which is a bug).
It's not (like other answers state) the comparison [textField.text isEqual:[NSNull null]] that leads to the bug. This line is nonsense, but can't result in the crash.
Search for places where you set the textfield's text property and check that the value is always of type NSString.
replace ([textField.text isEqual:[NSNull null]]) with (textField.text.length == 0).
According to your exception throw call stack, this crash is caused of by this method [textfield.text isEqual:[NSNull null]]`. You can use this code:
if (textfield.text){
}
Or
if ([textfield.text isEqualToString:#"your text"]){
}
textfield.text is an object which class is NSString and [NSNull null] is also an object that represent empty object.
I use DTHTMLAttributedStringBuilder of DTCoreText to display HTML code in UITableViewCell. But it has an error.
This is my code:
NSDictionary *builderOptions = #{DTDefaultFontFamily: #"Helvetica"};
DTHTMLAttributedStringBuilder *stringBuilder = [[DTHTMLAttributedStringBuilder alloc] initWithHTML:[word[#"name"] dataUsingEncoding:NSUTF8StringEncoding] options:builderOptions documentAttributes:nil];
NSAttributedString *stringAttri = [stringBuilder generatedAttributedString];
cell.textLabel.attributedText = stringAttri;
This is error:
[__NSCFType lineBreakMode]: unrecognized selector sent to instance 0x7f7f7bd1ba60
2015-06-06 11:16:38.898 PhrasalVerb[786:18798] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType lineBreakMode]: unrecognized selector sent to instance 0x7f7f7bd1ba60'
I had the same issue. Turns out I was trying to set the text on a UILabel and not a DTAttributedLabel.
Hi Guys i was wondering how to set the image of an UIimageView that is in a cell. I'm rather new to coding so please fully explain if u can. I currently have this:
cell.image.image = [tempObject objectForKey:#"CafeImage"];
But the app crashes with this everytime:
-[PFFile imageAsset]: unrecognized selector sent to instance 0x7a96cd80 2015-02-22 15:06:19.616 Cafe[12830:140389] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[PFFile imageAsset]: unrecognized selector sent to instance 0x7a96cd80'
It should be cell.imageView.image=[tempObject objectForKey:#"CafeImage"];
first - If you are using a standard cell, you should set
cell.imageView.image = "UIImage object";
second - Data in [tempObject objectForKey:#"CafeImage"] must be kind of UIImage class, or if it's NSString -> use [UIImage imageName:#"for example - objectForKey"];
In my app, I have created a 'NSMutalbeArray', in which I add some 'UILabel'.
I correctly initialize my array :
_pickerMonthLabel = [[NSMutableArray alloc] init];
I correctly add UILabels in my array, but when I want to make some changes to a label, the behavior is strange. For example, I want to change the text color of a label in my array. I do :
[(UILabel *)[_pickerMonthLabel objectAtIndex:i] setTextColor:[UIColor redColor]];
This doesn't look like to work because my app crashes :
-[__NSCFConstantString setTextColor:]: unrecognized selector sent to instance 0x17e8d4
*** Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[__NSCFConstantString setTextColor:]: unrecognized selector sent to instance 0x17e8d4'
But i have no warning when I wrote this line. When I write another kind of line :
(UILabel *)[_pickerMonthLabel objectAtIndex:i].textcolor = [UIColor redColor];
It gives me an error :
Property 'textcolor' not found on object of type 'id'
I don't understand the difference between these two lines, and how to fix my problem...
Thank you in advance for your help.
I guess this is more of a remark, but you could try to use the respondsToSelector: message to check if the instance can handle the message you are trying to send. (This will make sure you don't get an exception) In your case this would be:
if ([[_pickerMonthLabel objectAtIndex:i] respondsToSelector:#selector(setTextColor:)]){
[(UILabel *)[_pickerMonthLabel objectAtIndex:i] setTextColor:[UIColor redColor]];
}
// add this to see what your class is
//else{
// NSLog(#"The class is: %#", [[_pickerMonthLabel objectAtIndex:i] class]);
//}
Hope it helps your debugging.
i have created one custom cell and put button on it
and button event is like this
[cell.BtnRequest addTarget:self action:#selector(didTapButton:) forControlEvents:UIControlEventTouchUpInside];
and didtapbutton code is this
- (void)didTapButton:(id)sender {
WorkerDetailsVC *wvc=[self.storyboard instantiateViewControllerWithIdentifier:#"workerdetailsvc"];
NSIndexPath *indepath = [self.tblorderdata indexPathForCell:sender];
wvc.arrworkarrequest=[arrData objectAtIndex:indepath.row];
NSLog(#" arr send :%#", wvc.arrworkarrequest);
wvc.struserid = struserid;
[self.navigationController pushViewController:wvc animated:YES];
}
and on the next page i got the array arrworkarrequest and after the load all next page it will show error like this
2014-10-01 15:08:42.607 demo[2151:60b] -[__NSCFNumber length]: unrecognized selector sent to instance 0x911a860
2014-10-01 15:08:42.613 dmeo[2151:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber length]: unrecognized selector sent to instance 0x911a860'
Your problem is that sender is of type UIButton not UITableViewCell so it's getting stuck in the [self.tblorderdata indexPathForCell:sender] because that method call expects a type of UITableViewCell.
You need to find the Cell that the button is in. You may be able to do this using a while loop (although it's a bit horrible). Something like:
id obj = sender;
while (![obj isKindOfClass:[UITableViewCell class]]) {
obj = [sender superview];
}
[self.tblorderdata indexPathForCell:obj];
This feels like it's abusing the view hierarchy though.
This happens if you compare the length of a string directly
for example
NSString *myString = #"2";
using this statement will generate the error
if(myString.length==2)