Tag: nsstring

在视图控制器之间传递数据 – iOS Xcode – 什么是好方法?

好吧,我会试着尽可能简单(当我试着问这个问题时,我似乎在chat.stackoveflow.com上运行)。 我想将文本从一个视图控制器中的文本传递给另一个视图控制器。 我应该使用一个Model类,并将textfield.text存储在Model。[h / m]文件中,然后让第二个视图控制器访问存储在模型中的数据? 基本上这是我所拥有的, ViewControllerWelcome.h @interface ViewControllerWelcome : UIViewController { } @property (weak, nonatomic) IBOutlet UITextField *textFieldUsername; ViewControllerWelcome.m UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; ViewControllerHome *home = (ViewControllerHome *)[storyboard instantiateViewControllerWithIdentifier:@"Home"]; NSString *username = _textFieldUsername.text; home.lblUSERNAME.text=username; [self presentModalViewController:home animated:YES]; ViewControllerHome.h @interface ViewControllerHome : UIViewController { NSString *username; UILabel *lblUSERNAME; } @property (weak, nonatomic) IBOutlet […]

使用UIKit绘制复选标记NSString不会考虑填充颜色

我试图用UIKit绘制一个绿色的复选标记,但它是用黑色绘制的。 这里是代码: [[UIColor greenColor] set]; [@"✔" drawAtPoint:CGPointZero withFont:[UIFont systemFontOfSize:[UIFont systemFontSize]]]; 其他string用这种方法正确地绘制成绿色。 我怀疑复选标记符号包含的颜色信息覆盖了我select的填充颜色,但在UIWebView中使用颜色绘制相同的标志符号。 有没有办法让复选标记为绿色?

ARC和非ARC NSString初始化

最近,我在Objective-C / iOS程序中使用了自动引用计数function,并且真正享受了这个function。 有一件事我不明白这是正确的方法来初始化一个NSString 。 我已经看到这个方法与ARC和非ARC项目一起使用: NSString *myClassicString = [[NSString alloc] initWithFormat:@"My great non-ARC string!"]; 我也发现下面的方法可以用来初始化ARC中的NSString ,我更喜欢它,因为方便: NSString *myARCString = [NSString stringWithFormat:@"My new simple initialization string!"]; 这两者有什么区别? 有没有正确的方法? 是一个更好?

boundingRectWithSize的怪异行为:options:attributes:context:

我遇到一个与boundingRectWithSize:options:attributes:context:相关的奇怪问题boundingRectWithSize:options:attributes:context: 这是代码 NSString *text = @"These long strings work"; CGSize maxSize = CGSizeMake(176.0f, MAXFLOAT); CGRect rect = [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:16.0]} context:nil]; CGSize size = rect.size; 我有一个使用此代码的Xcode iOS项目。 当我运行这个项目时, size是(width=149.8125, height=18.1796875) 我在xcode中创build了一个新的单页应用程序项目,并在那里testing了相同的代码。 size是(width=172.944031, height=19.0880013) (它与在界面生成器中使用相同标题和相同字体创build的UILabel的帧大小相匹配) 苹果文档boundingRectWithSize:options:attributes:context : Calculates and returns the bounding rect for the receiver drawn using the given options and display […]

如何在iOS中将以下字符‡,†,*作为上标附加到NSString

我需要在iOS追加以下字符‡, †, *作为上标到NSString 。 需要你的帮助。 我使用下面的http://en.wikipedia.org/wiki/General_Punctuation_(Unicode_block)链接,但他们追加到NSString ,但我希望他们作为上标

NSSortDescriptor与任意sorting

我无法将自己的头围绕如何使用NSSortDescriptor进行任意sorting。 我想要做这样的事情: NSArray *sortAlgorithm = [NSArray arrayWithObjects:@"@", @"#", @"!", @"&", @"r", @"a", nil]; NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES comparator: ^(id obj1, id obj2) { NSComparisonResult comparisonResult; //Some code that uses sortAlgorithm. return comparisonResult; } ]; 这将通过键name对对象进行sorting,以便任何以@开始的键(例如@home )将出现在任何以r开头的键之前(例如radical ,并且再次以任何以a开头的键。 以上只是一个例子。 关键是要启用完全的任意sorting。 这将用于NSFetchedResultsController。 什么代码//使用sortAlgorithm的一些代码看起来像? 编辑: 代码围绕我尝试实现sortDescriptor,作为公关。 occulus'build议: – (NSFetchedResultsController *)fetchedResultsController { if (__fetchedResultsController) return __fetchedResultsController; […]

如何从NSString中删除hex字符

我面临一个问题相关的string中的一些hex值,我需要从NSString中删除hex字符。 问题是当我打印对象打印为“空白行”。 在debugging模式下,它显示如下: 那么我怎样才能从string中删除呢? 编辑 修剪空白: NSLog的结果是: 2015-12-14 15:37:10.710 MyApp [2731:82236] tmp:'' 数据库: 较早的问题: 如何检测ios中的垃圾string值?

NSString stringWithFormat很慢

在Objective-C中,方法stringWithFormat:似乎是非常慢,实际上是我们的一个应用程序(我们使用探查器找出来)的一个大瓶颈。 有没有一种方法来优化或使用更快的C代码?

我如何分割一个string到特殊字符到一个NSMutableArray

我试图把一个带有丹麦字符的string分隔成一个NSMutableArray。 但有些东西不起作用。 🙁 我的代码: NSString *danishString = @"æøå"; NSMutableArray *characters = [[NSMutableArray alloc] initWithCapacity:[danishString length]]; for (int i=0; i < [danishString length]; i++) { NSString *ichar = [NSString stringWithFormat:@"%c", [danishString characterAtIndex:i ]]; [characters addObject:ichar]; } 如果我在NSLog上执行了danishString,它就起作用(返回æ?); 但是如果我在字符(数组)上做一个NSLog,我会得到一些非常类似的字符 – 什么是错的? /莫滕

我如何从NSString获得课程?

例如,我有 NSString *myClass = @"RootViewController" 我如何从NSString获得课程?