1, 设置当前程序,使之可以自动运行.
a) NSMutableArray loginItems = (NSMutableArray) CFPreferencesCopyValue((CFStringRef)
"AutoLaunchedApplicationDictionary", (CFStringRef) "loginwindow",
kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
loginItems = [[loginItems autorelease] mutableCopy];
如此得到所有启动项,其中每个启动项都是个dictionary,启动项有2个key,分别是Hide(BOOL类型), Path(String类型)
b) 删除启动项则 [loginItems removeObject:anItem];
增加启动项则 [loginItems addObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO],"Hide", appPath, "Path", nil]];
注:appPath可以 = [[[NSBundle mainBundle] bundlePath] copy]
c) 最后,写回启动项去.
CFPreferencesSetValue((CFStringRef)
@"AutoLaunchedApplicationDictionary", loginItems, (CFStringRef)
@"loginwindow", kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
CFPreferencesSynchronize((CFStringRef) @"loginwindow",
kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
2, 窗口关闭之后,通过点击dock上的图标,再次显示一个窗口的做法.
- (BOOL)applicationShouldHandleReopen:(NSApplication )theApplication hasVisibleWindows:(BOOL)flag
{
if (flag)
return NO;
else
{
return YES;
}
}
3, 像sql语句一样,限制返回结果的条数,用setFetchLimit
// get the objects of the entites according predicate and sortDescriptors and limit
+ (NSArray *)objectsEntityForName:(NSString *)entityName
forPredicate:(NSPredicate *)predicate
forSortDescriptors:(NSArray)sortDescriptors
limit:(NSInteger)limit
{
NSEntityDescription *entity = [NSEntityDescription entityForName:entityName inManagedObjectContext:[NBCoreData managedObjectContext]];
NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
if(sortDescriptors)
NSArray *objects = [[NBCoreData managedObjectContext] executeFetchRequest:request error:nil]; }
return objects;
4, 高效的通知行高变化,如果你用[NSIndexSet indexSetWithIndexesInRange:0—rowsCount – 1]
NibiruTech based in Chengdu, China. This city has just survived from the May 12. 2008 earthquake. NibiruTech provides a promotion price, and 5% of this promotion income would be donated to Red Cross China.
Great web development services, very cost effective, We are extremely satisfied!
-William Gersham Meharg
Executive of E-xact Transactions
NibiruTech is one of the pioneers to use Ruby on Rails in China.
-Mike Meng, Chief Editor of Programmer Magazine