素墨文胤

一日心靜一日仙、不以神力亂人間


  • Startseite

  • Archiv

navigationItem的正确用法

Veröffentlicht am 2015-11-16 | Edited on 2018-01-23

今天设置一个 UITabBarController 管理下的 UIViewController 的 self.navigationItem.title 时怎么也设置不了(UITabBarController 在 UINavigationController 管理下),于是查官方 Documentation,发现如下文字:

1
2
3
@interface UIViewController (UINavigationControllerItem)
navigationItem Property
The navigation item used to represent the view controller in a parent'€™s navigation bar. (read-only)

然后设置 self.tabBarController.navigationItem.title 就有效了
顺便提一下,导航栏是其 viewControllers 共用的,所以 设置 navigationItem 要在 viewWillAppear 里,如果更改了 navigationBar,还要记得在 viewWillDisappear 的时候恢复原状。

CoreData的优化

Veröffentlicht am 2015-11-10 | Edited on 2018-01-23

//我对 mmDao 进行了修改,最终代码放在了:https://github.com/godera/HDCoreDataWrapper

【转帖,有修改】在多线程环境中使用CoreData
BY 子非鱼 · 2014 年 10 月 13 日

上回书说道,其实 CoreData 学起来也没有很复杂,它的增、删、改、查和别的 ORM 大同小异。但是世界总是很复杂的,一根筋的去考虑问题很容易卡到蛋,默认情况下我们的代码都在 Main Thread 中执行,数据库操作一旦量多了,频繁了,势必会阻塞住主线程的其他操作,俗语说–卡住了。

这个世界天然是多线程的,所以我们操作数据也必须多线程。CoreData 对多线程的支持比较奇怪(按照一般的思路来说),CoreData 的 NSPersistentStoreCoordinator 和 NSManagedObjectContext 对象都是不能跨线程使用的,NSManagedObject 也不行。有人想:加把锁不就完了?No!作为一个处女座是不能忍受这么丑陋的解决方案的。其实 NSManagedObjectContext 已经对跨线程提供了内置的支持,只不过方式比较特殊,需要脑洞大开才行。

Weiterlesen »

iOS 检测版本更新代码-OC

Veröffentlicht am 2015-11-06 | Edited on 2018-01-23
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
- (void)checkAppVersion {
NSDate *now = [NSDate date];
NSTimeInterval interval = [now timeIntervalSinceDate:[DataCenter singleton].appVerCheckDate];
if (interval < 24 * 60 * 60) {
// 一天内检测一次
return;
}

[DataCenter singleton].appVerCheckDate = now;

NSString *urlString = [NSString stringWithFormat:@"http://itunes.apple.com/cn/lookup?id=%@", @"你的 APP 的 apple id"];

[[AFHTTPSessionManager new] GET:urlString parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {

NSArray *infoArray = [responseObject objectForKey:@"results"];
if ([infoArray count]) {
NSDictionary *releaseInfo = [infoArray objectAtIndex:0];
NSString *onlineVersionString = [releaseInfo objectForKey:@"version"];
NSString *thisVersionString = [Utility versionRelease];

NSArray *onlineVersionComponents = [onlineVersionString componentsSeparatedByString:@"."];
NSArray *thisVersionComponents = [thisVersionString componentsSeparatedByString:@"."];

NSUInteger minCount = MIN(onlineVersionComponents.count, thisVersionComponents.count);
BOOL onlineVerGreaterThanThisVer = NO;
for (NSUInteger i = 0; i < minCount; i ++) {
NSUInteger onlineVersionBit = [onlineVersionComponents[i] integerValue];
NSUInteger thisVersionBit = [thisVersionComponents[i] integerValue];
if (onlineVersionBit == thisVersionBit) {
// 只要是相等就继续找下去,直至找到一个不相等的才能知道谁大谁小
continue;
}else{
if (onlineVersionBit > thisVersionBit) {
onlineVerGreaterThanThisVer = YES;
}else{
// onlineVersionBit < thisVersionBit
onlineVerGreaterThanThisVer = NO;
}
break;
}
}

if (onlineVerGreaterThanThisVer == NO && onlineVersionComponents.count > thisVersionComponents.count) {
onlineVerGreaterThanThisVer = YES;
}

if (onlineVerGreaterThanThisVer) {
NSLog(@"APP需要更新");
self.urlApp = [releaseInfo objectForKey:@"trackViewUrl"];
[HDAlertView showAlertwithTitle:HDLocalized(@"Note") message:HDLocalized(@"NewVersion") tiniColor:[CoreDataUpdateMethod sharedMethod].currentMoodColor delegate:self cancelButtonTitle:@"否" otherButtonTitles:@"是" ,nil].tag = 100102;
}
}

} failure:nil];
}

iOS修改工程名称和程序名称(Xcode6.3)

Veröffentlicht am 2015-10-10 | Edited on 2018-01-23

第一步:修改工程文件夹名称
第二步:打开新文件夹,将.xcodeproj更名,右键点击.xcodeproj并选择Show package contents,弹出一个对话框包含了几个文件.(事实上.xcodeproj是这几个文件打成的包)
第三步:用文本编辑器打开 project.pbxproj文件,将所有旧名字替换成为新的
第四步:把相应的文件夹名改成工程名,
第五步:这个时候可能会发现工程变成了mac工程,找到Manage Schemes功能,删除旧的重新建立Schemes即可

最后修改pch文件,.plist文件,test文件的名称,就OK了

从工程中删除CocoaPods

Veröffentlicht am 2015-10-10 | Edited on 2018-01-23
  1. 删除工程文件夹下的Podfile、Podfile.lock及Pods文件夹
  2. 删除xcworkspace文件
  3. 使用xcodeproj文件打开工程,删除Frameworks组下的Pods.xcconfig及libPods.a引用
  4. 在工程设置中的Build Phases下删除Check Pods Manifest.lock及Copy Pods Resources

ps:如果将cocoapods集成到工程中后不小心修改或删除了其相关文件导致无法便以通过例如:不小心把
Pods.xcconfig给删除了然后出现diff: /../Podfile.lock: No such file or directory,用上面的方法删除cocoapods后,
再重新 sudo pod install 一下就好了。
如果编译的时候出现权限问题,对工程文件夹$sudo chmod 777 path-to-project-folder/
$sudo chown 777 path-to-project-folder/

即可。

From:http://stackoverflow.com/questions/16427421/how-to-remove-cocoapods-from-a-project

【评】Cocoapods究竟有什么好?一款商用的软件必然追求代码稳定的,所以当有新代码进入的时候都应该做审查,用Cocoapods怎么做呢?更新安装的速度还那么慢!想来我们需要的是不时上github看我们关注的类库的更新,而不是Cocoapods。

听《水上致歌》(Auf dem Wasser zu singen)有感

Veröffentlicht am 2015-09-09 | Edited on 2018-01-23

  听《水上致歌》
临波望江水 思绪何茫茫
宿年陈旧事 尽皆翻澜沧
昔时君情薄 妾身常惶惶
今日君不忘 妾心自释放

侧面

Veröffentlicht am 2015-08-28 | Edited on 2018-01-23

“拿不定注意了吧?”
“你家墙是什么颜色的?”

iPhone屏幕适配

Veröffentlicht am 2015-06-01 | Edited on 2018-01-23

1.iPhone3GS屏幕 点数:320x480、像素数:320480,@1x
1.iPhone4屏幕 点数:320x480、像素数:640
960,@2x
1.iPhone5屏幕 点数:320x568、像素数:640x1136,@2x
1.iPhone6/7屏幕 点数:375x667、像素数:750x1334,@2x
1.iPhone6/7 Plus屏幕 点数:414x736、像素数:1242x2208,@3x(注意,在这个分辨率下渲染后,图像像素数降至1080p(1080x1920)

适配方案要点:
1、Size Classes 保持向后兼容:
size classes 为了保证向后兼容,需要高度(h)不能使用 紧凑(compact)类型,并且size class 在 xib 或故事版中被指定

2、使用 Auto Layout 布局

3、最好使用 @1-3x 图
pdf矢量图相对于固定的@1x、@2x、@3x图的优缺点: 1、pdf矢量图的大小比1x、2x、3x图的大小之和要小 2、pdf矢量图的文件数是1,1-3x有3个文件 3、pdf矢量图需要在build的时候自动生成1-3x图,有可能会失真,所以需要校对,并调整。

1…456…12

梁遜

一日心靜一日仙、不以神力亂人間

90 Artikel
10 Tags
© 2018 梁遜
Erstellt mit Hexo v3.4.4
|
Theme — NexT.Muse v6.2.0