为什么这不起作用?
if(typeof(localStorage.getItem("username"))=='undefined'){
alert('no');
};
Run Code Online (Sandbox Code Playgroud)
目标是将用户从索引页面重定向到登录页面(如果尚未记录).这里localStorage.getItem("username"))没有定义变量.
这是一个ios phonegap应用程序.
我想将属性添加到NSString对象.出于这个原因,我想继承它.
我尝试做这样的事情:
@interface MyString : NSString
@property (nonatomic) NSInteger userId;
@end
Run Code Online (Sandbox Code Playgroud)
所以我能做到
MyString *testString = [[MyString alloc] init];
testString = [MyString stringWithFormat:@"hello"];
testString.userId = 2;
NSLog(@"testString: %@", testString); //-> Want it to return "testString: hello"
NSLog(@"userId: %d", testString.userId); //-> Want it to return "userId: 2"
Run Code Online (Sandbox Code Playgroud)
我不知道如何子类NSString(创建存储设施,覆盖一些方法(length,characterAtIndex).有想法吗?
我的视图控制器中有一个 UITableView 和一个 UISegmentControl。视图控制器有两个部分。当用户点击一个段时,我在 viewController 中细化数据,它应该在 UITableView 中更新。这不起作用。
数据使用 NSFetchedResultsController 显示,其数据源是 CoreData 表。它们使用相同的 NSSortDescriptor,但不相同的谓词。
我观察到当我更改 NSSortDescriptor 时,它可以工作,所以这个对象是问题的根源。
当用户点击一个段时,我调用这个代码:
self.fetchedResultsController = nil;
NSError *error;
if (![[self fetchedResultsController] performFetch:&error]) {
// Update to handle the error appropriately.
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
exit(-1); // Fail
}
Run Code Online (Sandbox Code Playgroud)
它以这种方式更新 NSFetchedResultsController:
- (NSFetchedResultsController *)fetchedResultsController {
if (_fetchedResultsController != nil) {
return _fetchedResultsController;
}
//get the segment index:
NSUInteger selectedState = self.chooseTableSegmentedControl.selectedSegmentIndex;
//Update the fetched result consequently:
NSManagedObjectContext *context = self.managedObjectContext;
NSFetchRequest *fetchRequest = …Run Code Online (Sandbox Code Playgroud)