我写了一个简单的 ios5 应用程序(包括垃圾收集器),它有一个单一的视图,UITextField
我需要分析输入文本,这UITextField
是我的代码。头文件:
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UITextFieldDelegate>
{
IBOutlet UITextField *myTextField;
}
@property (nonatomic, retain) IBOutlet UITextField *myTextField;
-(IBAction)editingChanged:(UITextField *)sender;
editingChanged:
跟踪发送事件编辑更改,因此每次用户更改我的某些内容时都会调用此方法UITextField
部分实现文件:
#pragma mark - textField
-(NSString *)stringWithoutAbc:(NSString *)sourceString
{
NSString *resultString=[sourceString stringByReplacingOccurrencesOfString:@"abc:" withString:@""];
if (![resultString isEqualToString:sourceString])
{
NSLog(@" sourceString: %@", sourceString);
NSLog(@" resultString: %@", resultString);
};
return resultString;
}
-(IBAction)editingChanged:(UITextField *)sender
{
NSLog(@"editing Changed. text: %@", sender.text);
//removing "abc:" from string in text field
NSString *str=[self stringWithoutAbc:sender.text];
//if something was removed - changing text in text field
if (![str isEqualToString:sender.text])
{
sender.text=str;
};
}
每次用户更改文本时,我们都会使用标准方法UITextField
从该文本中删除“abc:”字符串。NSString
问题是:应用程序不稳定。当“abc:”被删除时,它有时会崩溃。请帮帮我。如何解决这个问题呢?