我有两个问题.
如果我理解本地通知,则重复间隔允许我安排一次通知,并且每周或每月或每周的同一时间间隔重复通知.我想在星期二开始重复一次重复间隔,每周它会在同一天即星期二再次开火.这应该每周进行,而无需安排另一个通知.那是对的吗.是不是发生了.我要么在代码中做错了,要么我测试错了.
在模拟器中,我运行app安排通知.我看到了通知.然后我退出应用程序并在未来的同一天将系统日期设置为1周但没有通知,因此我可以通过更改计算机系统时钟以这种方式测试此通知.我不想每个测试都要等一个星期.
这是代码
- (void) scheduleNotificationWithItem:(NSDate *)date interval:(int)frequency {
UILocalNotification *localNotif = [[UILocalNotification alloc]init];
if (localNotif == nil) {
return;
}
localNotif.fireDate = [date addTimeInterval:frequency];
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.repeatCalendar = [NSCalendar currentCalendar];
localNotif.repeatInterval = kCFCalendarUnitWeekday;
localNotif.applicationIconBadgeNumber = 1;
localNotif.alertBody = [NSString stringWithFormat:NSLocalizedString(@"%@.",nil),@"Weekly Reminder"];
localNotif.alertAction = NSLocalizedString(@"View Notification Details", nil);
localNotif.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication]scheduleLocalNotification:localNotif];
[localNotif release];
}
Run Code Online (Sandbox Code Playgroud)
请帮助这让我发疯.谢谢,迪恩
我想将输入限制为仅用户名字段的英文字母(az).有人可以帮我添加下面的代码,不允许输入除英文字母以外的任何数字,字符和任何其他语言吗?
现在,下面的代码不允许使用空格,也不允许输入超过10个字母.
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
{
BOOL _isAllowed = YES;
NSString *nameRegex = @"[A-Za-z]+";
NSPredicate *nameTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", nameRegex];
NSString *tempString = [[textField.text stringByReplacingCharactersInRange:range withString:string] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if (textField == self.usernameField)
{
if ([self.usernameField.text isEqualToString:tempString])
{
self.title.text = @"No Spaces Allowed";
self.title.textColor = [UIColor yellowColor];
_isAllowed = NO;
}
else if (tempString.length > 10)
{
self.title.text = @"Username cannot be more than 10 letters.";
self.title.textColor = [UIColor yellowColor];
_isAllowed = NO;
}
Run Code Online (Sandbox Code Playgroud)
更新 …
按步骤一步一步完成:http: //www.raywenderlich.com/12139/introduction-to-cocoapods
pod install在不同的项目中运行时出错:
### Stack
```
CocoaPods : 0.15.2
Ruby : ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.0]
RubyGems : 1.8.24
Host : Mac OS X 10.8.2 (12C60)
Xcode : 4.5.2 (4G2008a)
Ruby lib dir : /usr/local/rvm/rubies/ruby-1.9.3-p194/lib
Repositories : master - https://github.com/CocoaPods/Specs.git @ 60b51e341f727b7d715ed541ea9cb52f6e0cc819
```
### Podfile
```ruby
platform :ios, '6.0'
pod 'AFNetworking', '1.0'
```
### Error
```
invalid byte sequence in US-ASCII
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/cocoapods-0.15.2/lib/cocoapods/local_pod.rb:540:in `glob'
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/cocoapods-0.15.2/lib/cocoapods/local_pod.rb:540:in `glob'
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/cocoapods-0.15.2/lib/cocoapods/local_pod.rb:540:in `block in expanded_paths'
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/cocoapods-0.15.2/lib/cocoapods/local_pod.rb:534:in `map'
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/cocoapods-0.15.2/lib/cocoapods/local_pod.rb:534:in `expanded_paths'
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/cocoapods-0.15.2/lib/cocoapods/local_pod.rb:327:in `readme_file' …Run Code Online (Sandbox Code Playgroud) var searchDelayer:NSTimer?
func searchBar(searchBar: UISearchBar!, textDidChange searchText: String!) {
searchDelayer?.invalidate()
searchDelayer = nil
searchDelayer = NSTimer.scheduledTimerWithTimeInterval(1.5, target: self, selector: Selector("doDelayedSearch:"), userInfo: searchText, repeats: false)
}
func doDelayedSearch(text:String){
...
}
Run Code Online (Sandbox Code Playgroud)
为什么此代码崩溃并显示错误消息:
[__NSCFTimer copyWithZone:]: unrecognized selector sent to instance
Run Code Online (Sandbox Code Playgroud)
更新:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFTimer copyWithZone:]: unrecognized selector sent to instance 0x7f9c622ae7e0'
*** First throw call stack:
(
0 CoreFoundation 0x000000010c05b3e5 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010ba42967 objc_exception_throw + 45
2 CoreFoundation 0x000000010c0624fd -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 …Run Code Online (Sandbox Code Playgroud) objective-c ×2
character ×1
cocoapods ×1
ios ×1
ios6 ×1
ios8 ×1
nstimer ×1
swift ×1
uitextfield ×1