nsstring

iOS special characters, strange issue

我的梦境 提交于 2020-01-16 18:18:13
问题 I've got a very strange issue. I started an iOS App about three years ago (iOS-SDK 3.0), and since then went through the SDKs 4.0 and 5.0. Since 5.0 (or maybe 5.1) I suddenly started having problems with German special chars (ä ö ü ß). Now I can't even initialize an NSString with special chars, this line: NSString *str = @"abcäxyz"; gives the following warning: Input conversion stopped due to an input byte that does not belong to the input codeset UTF-8 And this one: NSLog(@"%@", strTemp);

iPhone Digital Clock

亡梦爱人 提交于 2020-01-16 13:27:28
问题 After the long time I spent getting an analog clock to work, I am trying to make a digital one ( sigh ). I am trying to do this with 10 PNGs with the numbers 0 - 9. Each digit of the clock would be an image. The only problem with this is retrieving the certain digit from the current time. I've tried converting the time to a string and using the characterAtIndex, but that doesn't seem to work. What would be the best way to get around this? 回答1: You could use NSDateComponents and NSCalendar :

Transform NSData to int in Objective-c

≡放荡痞女 提交于 2020-01-16 10:03:55
问题 I would like to transform NSData to int in Objective-c. In the following code, "index2" is "15", but "value" is "0". (NSLog says "15,0".) To be exact, "value" must be "15". NSString *index = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; NSString *index2 = [index stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; int value = [index2 intValue]; NSLog(@"%@,%d",index2,value); Could you tell me how to solve this problem? 回答1: If you want to

Transform NSData to int in Objective-c

一曲冷凌霜 提交于 2020-01-16 10:03:13
问题 I would like to transform NSData to int in Objective-c. In the following code, "index2" is "15", but "value" is "0". (NSLog says "15,0".) To be exact, "value" must be "15". NSString *index = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; NSString *index2 = [index stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; int value = [index2 intValue]; NSLog(@"%@,%d",index2,value); Could you tell me how to solve this problem? 回答1: If you want to

iOS开发 给TableView增加SearchBar

无人久伴 提交于 2020-01-16 04:33:36
效果如图: 可以根据输入的关键字,在TableView中显示符合的数据。 图中分组显示和索引效果,前面的博文已经记录,不再赘述。下面的例子是基于前文的基础上修改的,所以文件名啥的,请参考前文。 第一步是在TableView上方添加一个Search Bar,这里有一点需要注意,必须先把TableView拖下来,留下空间放Search Bar,不要在Table View占满屏幕的情况下把Search Bar拖到Table View顶部。区别在于,使用后面的方法,Search Bar是作为Table View的Header部分添加的,而前面的方法,Search Bar是独立的。在添加索引功能时,如果作为Table View的Header添加,右侧的索引会遮住Search Bar的右边部分。Search Bar几个常用属性: Placeholder是提示,就是hint属性,Corretion是自动修正,一般设为NO,即不修正,Show Cancel Button是显示取消按钮,我这里勾选。选中Search Bar的情况下切换到Connections Inspector面板,delegate与File’s Owner建立连接(我们会在ViewController中支持UISearchBarDelegate协议)。与前面几篇文章的例子相 同

How can I disable the decimal key on iOS keyboard

一曲冷凌霜 提交于 2020-01-16 01:03:37
问题 I want to disable the "." key on the number pad after detecting that the user already has entered in one decimal point into the textfield. So the key is enabled until one decimal is detected in the textfield. What is the best way of doing this? EDIT: I've implemented the method below: - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { if([string isEqualToString:@"."]) { decimalCount++; } if(decimalCount > 1) { [string

Write to file does not work [duplicate]

余生颓废 提交于 2020-01-16 01:02:24
问题 This question already has answers here : File write with [NSBundle mainBundle] fails (5 answers) Closed 6 years ago . When i try to write to file with this code: NSString *path = [[NSBundle mainBundle] pathForResource:@"default" ofType:@"txt"]; NSError *error = nil; NSString*s = @"some text"; BOOL successful = [s writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:&error]; NSLog(@"%@",error); NSLog(@"%d",successful); Nothing happens. NSLog says: (null) 1 回答1: That's because

Decoding the scanned barcode value to int value

可紊 提交于 2020-01-16 00:54:12
问题 When I scan the barcode and I get some value if it is Equal=2 then I need to display with == and if it is Equal=3 then I need to display with = and if the value is 4 then invalid. But Scanned Barcode are of integer value -- when decode using NSASCII it is displaying only till value 127 after that it is showing invalid results. Eg: if my Barcode value = 9699 the result value= jem then my added result value= jem= actualstring value= %å asc value id only showing 37 Here is my code: - (void)

Display edited NSString in order

六月ゝ 毕业季﹏ 提交于 2020-01-15 12:13:51
问题 I have been working on this for a few days with help from this great community. I have a NSArray that I need to edit NSStrings within. I have managed to detect a marker in the string and make it bold. However now I am trying to display the strings in the order that they are within the NSArray whilst maintaining the Bold that was added to the specific strings. I can display the individual Bold String ' string ' but I need it to be in order that it is within the array. I know of

Display edited NSString in order

霸气de小男生 提交于 2020-01-15 12:13:43
问题 I have been working on this for a few days with help from this great community. I have a NSArray that I need to edit NSStrings within. I have managed to detect a marker in the string and make it bold. However now I am trying to display the strings in the order that they are within the NSArray whilst maintaining the Bold that was added to the specific strings. I can display the individual Bold String ' string ' but I need it to be in order that it is within the array. I know of