Wrong UILabel Hebrew text - iphone

Good day, the problem is this - I have to get a string from the server:
שיעור ראשון - הרב חגי לונדין but when try do NSLog i saw - ׳¢׳¨׳•׳¥ ׳׳׳™׳¨ - ׳׳•׳׳׳¦׳™׳ ׳“׳£ ׳”׳‘׳™׳×
or \U05f3\U201c\U05f3\U2018; I try set Hebrew language to my UILabel;
cell.titleLabel.text = [[feeds objectAtIndex:indexPath.row] objectForKey:#"title"];
Please Help Me.

Related

How to replace text in UITextView with selected range?

I want to replace the text in UITextView text in selected range. This is my question. Here i mention what i did? and what i want to do?. I have an UITextView and entered the below text in textview.
Ask question here, i have saved the range in of the text in textview. The text range is {17, 0}. I take the NSRange in -(void) textViewDidChange:(UITextView *)textView delegate.
Now i want to replace the text question with answer and i want to replace the text here with them. The UITextView.text look like this,Ask answer them` after replaced the texts.
How can i replace the texts with the selected ranges? Can you please help me? Thanks in advance.
Since iOS 7 there is the textStorage in the textView that inherits from NSMutableAttributedString so you can use those methods:
Objective-C
[self.textView.textStorage replaceCharactersInRange:withString:];
or
[self.textView.textStorage replaceCharactersInRange:withAttributedString:];
Swift
textView.textStorage.replaceCharacters(in: range, with: string)
Well... I'm not sure to understand correctly what you're trying to do, but if your goal is to change some characters in a selected range you can follow these steps:
Get your UITextView content and put it in a NSString:
NSString *textViewContent = textView.text;
Change the characters in the range you want:
NSString *newContent = [textViewContent stringByReplacingCharactersInRange:range withString:replacement];
Replace old content with new one:
textView.text = newContent;
Anyway if you just want to replace Ask question here with Ask answer them the fastest solution is just:
textView.text = #"Ask answer them";
Well solution from top of my head..
NSArray *Dividedstring = [[self.TextView.text] componentsSeparatedByString:#" question here "]; // this will divide the string into two parts ..one before question here and second after question here.
NSString * firstpart = [Dividedstring objectAtIndex:0];
NSString * secondpart = [Dividedstring objectAtIndex:0];
self.TextView.text = [NSString stringwithFormat:#"%# answer here %#",firstpart,secondpart];

iOS: Highlight spelling errors but disable suggestions?

My app implements a custom spell checker with its own window and a different workflow from the built-in spell checker in iOS. Therefore I have switched off correction in the main text input view. This disables the built-in suggestions, but also the highlighting of misspelled words.
Is there a way to keep the highlighting, but disable the suggestions?
You can use below code to check weather the printed word is correct spelled or not and if wrong then highlight that word
first import
#import <UIKit/UITextChecker.h>
in your file
-(BOOL)isDictionaryWord:(NSString*)word {
UITextChecker *checker = [[UITextChecker alloc] init];
NSLocale *currentLocale = [NSLocale currentLocale];
NSString *currentLanguage = [currentLocale objectForKey:NSLocaleLanguageCode];
NSRange searchRange = NSMakeRange(0, [word length]);
NSRange misspelledRange = [checker rangeOfMisspelledWordInString:word range: searchRange
startingAt:0 wrap:NO language: currentLanguage ];
return misspelledRange.location == NSNotFound;
}
You will have to roll your own. Here's a rough (iOS 5 and later):
Drop a view with transparent background on top of the text view.
Find the visible range of text like so:
- (NSRange)visibleRangeOfTextView:(UITextView *)textView {
CGRect bounds = textView.bounds;
UITextPosition *start = [textView characterRangeAtPoint:bounds.origin].start;
UITextPosition *end = [textView characterRangeAtPoint:CGPointMake(CGRectGetMaxX(bounds), CGRectGetMaxY(bounds))].end;
return NSMakeRange([textView offsetFromPosition:textView.beginningOfDocument toPosition:start],
[textView offsetFromPosition:start toPosition:end]);
}
Search for misspelled words in that range.
Find their on-screen coordinates using UITextView firstRectForRange method.
Highlight any way you want.
Deciding when to do this is left as an exercise for the eager student :)

How do I do decimal formatting in Objective-C?

Pretty new to the whole iPhone development scene. I am just practicing, trying to create a basic calculator, I can add simple numbers but I'd like to support decimal places.
Heres my code so far:
- (IBAction) calculate
{
double number1 = ([textField.text doubleValue]);
double answer = number1+([textField2.text doubleValue]);
label.text = [[NSString alloc] initWithFormat:#"%2.f", answer];
}
- (IBAction) clear
{
textField.text = #"";
textField2.text = #"";
label.text = #"";
}
Any help much appreciated.
I think your format might be wrong. What is the output you're expecting, and what are you getting?
If I'm guessing correctly, you may want to try this:
label.text = [NSString stringWithFormat:#"%5.2f", answer];
where the 5 means total digits (in terms of padding for alignment), and the 2 means 2 decimal places.
EDIT: avoiding memory leak, as mentioned in donkim's comment!

Text not being displayed correctly due to code formatted wrong maybe?

I have NSMutableDictionary that I'm retrieving text from. I"m trying to display this text into a tableview cell along with some other text that I want added with it. Here's my non-working code:
[[cell name] setText:(#"Name:%#",[NameDict valueForKey:#"name"])];
I've even tried stringWithFormat and still can't get it to work. I can't get the Name: part to display into the cell along with NameDict value for that key. Any ideas what I'm doing wrong here? Thanks.
I'm not sure where you are getting [cell name] from, but this would be a better solution for you based on your code:
[[cell name] setText:[NSString stringWithFormat:#"Name:%#",[NameDict objectForKey:#"name"]]];
If you are trying to place that text as the cell text, use:
cell.textLabel.text = [NSString stringWithFormat:#"Name:%#",[NameDict objectForKey:#"name"]];

Iphone sizewithfont doesn't work?

I have the following code:
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *currentMessage = [FeedMessages objectAtIndex:indexPath.row];
NSLog(currentMessage);
UIFont *font = [UIFont systemFontOfSize:14];
NSLog([NSString stringWithFormat:#"Height: %#",[currentMessage sizeWithFont:font forWidth:270 lineBreakMode:UILineBreakModeWordWrap].height]);
return [currentMessage sizeWithFont:font forWidth:270 lineBreakMode:UILineBreakModeWordWrap].height;
}
Can anybody tell me why "[currentMessage sizeWithFont:font forWidth:270 lineBreakMode:UILineBreakModeWordWrap].height" is always returning null or nil?
I've checked and currentMessage is populated correctly.
Any ideas?
Go through this question. It describes that - you must have to use, CGFLOAT_MAX or see following code ( grabbed from there . )
NSString *text = #"A really long string in here";
CGSize theSize = [text sizeWithFont:[UIFont boldSystemFontOfSize:18.0f] constrainedToSize:CGSizeMake(265.0f, CGFLOAT_MAX) lineBreakMode:UILineBreakModeWordWrap];
NSString *stringHeight = [NSString stringWithFormat:#"%f", theSize.height];
You are not using NSLog() in correct format. it should be
NSLog(#" %#",[NSString stringWithFormat:#"Height: %f",[currentMessage sizeWithFont:font forWidth:270 lineBreakMode:UILineBreakModeWordWrap].height]);
and %f should be used for float.
Apart from your flawed type juggling which has been noted above, sizeWithFont:forWidth:lineBreakMode: only measures dimensions of the (truncated) first line, oddly enough.
you want to use sizeWithFont:constrainedToSize:lineBreakMode: which actually splits text over lines and takes the lines into account. Use a CGSizeMake(270.0f,999999.0f) to get the full height of the text.
see http://developer.apple.com/iphone/library/documentation/uikit/reference/NSString_UIKit_Additions/Reference/Reference.html
I spent 2 hours on this, freaking out. For me the problem was in such a small and stupid thing: I had a 'release' mode switched on. So, when going with debugger, it was stopping at the proper code lines (no idea why debugger should do that in release mode), but didn't show what I expected.