application:didFinishLaunchingWithOptions:applicationWillResignActive:applicationDidEnterBackground:applicationWillEnterForeground:applicationDidBecomeActive:applicationWillTerminate:
Incident Identifier: 30E46451-53FD-4965-896A-457FC11AD05FCrashReporter Key: 5a56599d836c4f867f6eec76afee451bf9ae5f31Hardware Model: iPhone4,1Process: Rage Masters [4155]Path: /var/mobile/Applications/A5635B22-F5EF-4CEB-94B6-FE158D885014/Rage Masters.app/Rage MastersIdentifier: Rage MastersVersion: ??? (???)Code Type: ARM (Native)Parent Process: launchd [1]// 2: 基本信息Date/Time: 2012-10-17 21:39:06.967 -0400OS Version: iOS 6.0 (10A403)Report Version: 104// 3: 异常Exception Type: 00000020Exception Codes: 0x000000008badf00dHighlighted Thread: 0// 4: 线程回溯Thread 0 name: Dispatch queue: com.apple.main-threadThread 0:0 libsystem_kernel.dylib 0x327f2eb4 mach_msg_trap + 201 libsystem_kernel.dylib 0x327f3048 mach_msg + 362 CoreFoundation 0x36bd4040 __CFRunLoopServiceMachPort + 1243 CoreFoundation 0x36bd2d9e __CFRunLoopRun + 8784 CoreFoundation 0x36b45eb8 CFRunLoopRunSpecific + 3525 CoreFoundation 0x36b45d44 CFRunLoopRunInMode + 1006 CFNetwork 0x32ac343e CFURLConnectionSendSynchronousRequest + 3307 Foundation 0x346e69ba +[NSURLConnection sendSynchronousRequest:returningResponse:error:] + 2428 Rage Masters 0x000d4046 0xd2000 + 8262Thread 1:0 libsystem_kernel.dylib 0x32803d98 __workq_kernreturn + 81 libsystem_c.dylib 0x3a987cf6 _pthread_workq_return + 142 libsystem_c.dylib 0x3a987a12 _pthread_wqthread + 3623 libsystem_c.dylib 0x3a9878a0 start_wqthread + 4// 5: 线程状态Thread 0 crashed with ARM Thread State (32-bit): r0: 0x00000000 r1: 0x00000000 r2: 0x00000001 r3: 0x39529fc8 r4: 0xffffffff r5: 0x2fd7d301 r6: 0x2fd7d300 r7: 0x2fd7d9d0 r8: 0x2fd7d330 r9: 0x3adbf8a8 r10: 0x2fd7d308 r11: 0x00000032 ip: 0x00000025 sp: 0x2fd7d2ec lr: 0x001bdb25 pc: 0x30301838 cpsr: 0x00000010// 6: 二进制映像Binary Images:0xd2000 - 0xd7fff +Rage Masters armv7 /var/mobile/Applications/A5635B22-F5EF-4CEB-94B6-FE158D885014/Rage Masters.app/Rage Masters0x2fe41000 - 0x2fe61fff dyld armv7 /usr/lib/dyld0x327f2000 - 0x32808fff libsystem_kernel.dylib armv7 /usr/lib/system/libsystem_kernel.dylib0x328a8000 - 0x328bdfff libresolv.9.dylib armv7 /usr/lib/libresolv.9.dylib0x32a70000 - 0x32b35fff CFNetwork armv7 /System/Library/Frameworks/CFNetwork.framework/CFNetwork0x32b7a000 - 0x32cc3fff libicucore.A.dylib armv7 /usr/lib/libicucore.A.dylib0x32cc4000 - 0x32cc5fff CoreSurface armv7 /System/Library/PrivateFrameworks/CoreSurface.framework/CoreSurface0x32f65000 - 0x32f8afff OpenCL armv7 /System/Library/PrivateFrameworks/OpenCL.framework/OpenCL
2 XYZLib 0x34648e88 0x83000 + 8740
6 Rage Masters 0x0001625c 0x2a000 + 3003
6 Rage Masters 0x0001625c -[RMAppDelegate application:didFinishLaunchingWithOptions:] (RMAppDelegate.m:35)
强势插入:在编译.app后与.app同根目录文件夹下会有一个对应的.dSYM文件,要养成一个好习惯,发布一版app时同时保存对应的.dSYM文件。
Incident Identifier: 30E46451-53FD-4965-896A-457FC11AD05FCrashReporter Key: 5a56599d836c4f867f6eec76afee451bf9ae5f31OS Version: iPhone OS 3.1.3 (7E18)Date/Time: 2012-10-17 21:39:06.967 -0400Free pages: 96Wired pages: 10558Purgeable pages: 0Largest process: Rage MastersProcesses Name UUID Count resident pages Rage Masters 9320 (jettisoned) (active) mediaserverd 255 dataaccessd 505 syslogd 71 apsd 171 securityd 243 notifyd 2027 CommCenter 189 SpringBoard 2158 (active) accessoryd 91 configd 371 fairplayd 93 mDNSResponder 292 lockdownd 1204 launchd 72
Incident Identifier: 85833DBA-3DF7-43EE-AF80-4E5C51091F42CrashReporter Key: 5a56599d836c4f867f6eec76afee451bf9ae5f31Hardware Model: iPhone4,1Process: Rage Masters [20067]Path: /var/mobile/Applications/B2121A89-3D1F-4E61-BB18-5511E1DC150F/Rage Masters.app/Rage MastersIdentifier: Rage MastersVersion: ??? (???)Code Type: ARM (Native)Parent Process: launchd [1]Date/Time: 2012-11-03 13:37:31.148 -0400OS Version: iOS 6.0 (10A403)Report Version: 104Exception Type: 00000020Exception Codes: 0x000000008badf00dHighlighted Thread: 0Application Specific Information:Soheil-Azarpour.Rage-Masters failed to launch in timeElapsed total CPU time (seconds): 8.030 (user 8.030, system 0.000), 20% CPU Elapsed application CPU time (seconds): 3.840, 10% CPUThread 0 name: Dispatch queue: com.apple.main-threadThread 0:0 libsystem_kernel.dylib 0x327f2eb4 mach_msg_trap + 201 libsystem_kernel.dylib 0x327f3048 mach_msg + 362 CoreFoundation 0x36bd4040 __CFRunLoopServiceMachPort + 1243 CoreFoundation 0x36bd2d9e __CFRunLoopRun + 8784 CoreFoundation 0x36b45eb8 CFRunLoopRunSpecific + 3525 CoreFoundation 0x36b45d44 CFRunLoopRunInMode + 1006 CFNetwork 0x32ac343e CFURLConnectionSendSynchronousRequest + 3307 Foundation 0x346e69ba +[NSURLConnection sendSynchronousRequest:returningResponse:error:] + 2428 Rage Masters 0x000ea1c4 -[RMAppDelegate application:didFinishLaunchingWithOptions:] (RMAppDelegate.m:36)9 UIKit 0x37f30ad4 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 24810 UIKit 0x37f3065e -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 118611 UIKit 0x37f28846 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 69412 UIKit 0x37ed0c3c -[UIApplication handleEvent:withNewEvent:] + 100013 UIKit 0x37ed06d0 -[UIApplication sendEvent:] + 6814 UIKit 0x37ed011e _UIApplicationHandleEvent + 615015 GraphicsServices 0x370835a0 _PurpleEventCallback + 58816 GraphicsServices 0x370831ce PurpleEventCallback + 3017 CoreFoundation 0x36bd4170 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 3218 CoreFoundation 0x36bd4112 __CFRunLoopDoSource1 + 13419 CoreFoundation 0x36bd2f94 __CFRunLoopRun + 138020 CoreFoundation 0x36b45eb8 CFRunLoopRunSpecific + 35221 CoreFoundation 0x36b45d44 CFRunLoopRunInMode + 10022 UIKit 0x37f27480 -[UIApplication _run] + 66423 UIKit 0x37f242fc UIApplicationMain + 111624 Rage Masters 0x000ea004 main (main.m:16)25 libdyld.dylib 0x3b630b1c start + 0
Application Specific Information:Soheil-Azarpour.Rage-Masters failed to launch in timeElapsed total CPU time (seconds): 8.030 (user 8.030, system 0.000), 20% CPU Elapsed application CPU time (seconds): 3.840, 10% CPU
8 Rage Masters 0x0009f244 -[RMAppDelegate application:didFinishLaunchingWithOptions:] (RMAppDelegate.m:35)
NSData *directoryData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
就是它了! 同步调用web服务?! 在主线程上?! 在 application:didFinishLaunchingWithOptions: 方法上?!! 谁写的代码呀?!
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { NSURL *cacheDirectory = [[[NSFileManager defaultManager] URLsForDirectory:NSUserDirectory inDomains:NSCachesDirectory] lastObject]; NSURL *filePath = [NSURL URLWithString:kDirectoryFile relativeToURL:cacheDirectory]; [data writeToFile:[filePath absoluteString] atomically:YES]; }];
Incident Identifier: 3AAA63CC-3088-41CC-84D9-82FE03F9F354CrashReporter Key: 5a56599d836c4f867f6eec76afee451bf9ae5f31Hardware Model: iPhone4,1Process: Rage Masters [20090]Path: /var/mobile/Applications/B2121A89-3D1F-4E61-BB18-5511E1DC150F/Rage Masters.app/Rage MastersIdentifier: Rage MastersVersion: ??? (???)Code Type: ARM (Native)Parent Process: launchd [1]Date/Time: 2012-11-03 13:39:00.081 -0400OS Version: iOS 6.0 (10A403)Report Version: 104Exception Type: EXC_CRASH (SIGABRT)Exception Codes: 0x0000000000000000, 0x0000000000000000Crashed Thread: 0Last Exception Backtrace:0 CoreFoundation 0x36bff29e __exceptionPreprocess + 1581 libobjc.A.dylib 0x34f0f97a objc_exception_throw + 262 CoreFoundation 0x36c02e02 -[NSObject(NSObject) doesNotRecognizeSelector:] + 1663 CoreFoundation 0x36c0152c ___forwarding___ + 3884 CoreFoundation 0x36b58f64 _CF_forwarding_prep_0 + 205 UIKit 0x37fbb0a8 -[UIApplication sendAction:to:from:forEvent:] + 686 UIKit 0x37fbb05a -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 267 UIKit 0x37fbb038 -[UIControl sendAction:to:forEvent:] + 408 UIKit 0x37fba8ee -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 4989 UIKit 0x37fbade4 -[UIControl touchesEnded:withEvent:] + 48410 UIKit 0x37ee35f4 -[UIWindow _sendTouchesForEvent:] + 52011 UIKit 0x37ed0804 -[UIApplication sendEvent:] + 37612 UIKit 0x37ed011e _UIApplicationHandleEvent + 615013 GraphicsServices 0x3708359e _PurpleEventCallback + 58614 GraphicsServices 0x370831ce PurpleEventCallback + 3015 CoreFoundation 0x36bd416e __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 3016 CoreFoundation 0x36bd4112 __CFRunLoopDoSource1 + 13417 CoreFoundation 0x36bd2f94 __CFRunLoopRun + 138018 CoreFoundation 0x36b45eb8 CFRunLoopRunSpecific + 35219 CoreFoundation 0x36b45d44 CFRunLoopRunInMode + 10020 GraphicsServices 0x370822e6 GSEventRunModal + 7021 UIKit 0x37f242fc UIApplicationMain + 111622 Rage Masters 0x000ca004 main (main.m:16)23 libdyld.dylib 0x3b630b1c start + 0
2 CoreFoundation 0x36c02e02 -[NSObject(NSObject) doesNotRecognizeSelector:] + 166
这不是你自己写的代码。但至少它确认了是对象调用了一个没有实现的方法。
-(IBAction)bookmarkButtonPressed { self.master.isBookmarked = !self.master.isBookmarked; // Update shared bookmarks if (self.master.isBookmarked) [[RMBookmarks sharedBookmarks] bookmarkMaster:self.master]; else [[RMBookmarks sharedBookmarks] unbookmarkMaster:self.master]; // Update UI [self updateBookmarkImage];}
看起来没什么问题,再检查一下storyboard (XIB文件) ,确认按钮连接的正确性。
-(IBAction)bookmarkButtonPressed:(id)sender { // Remain unchanged..}
当然,你也可以简单地在XIB文件上删除错误的连接,然后重新连接方法,使XIB文件连接到正确的方法上。两者方法都行。
Incident Identifier: 5B62D681-D8FE-41FE-8D52-AB7E6D6B2AC7CrashReporter Key: 5a56599d836c4f867f6eec76afee451bf9ae5f31Hardware Model: iPhone4,1Process: Rage Masters [20088]Path: /var/mobile/Applications/B2121A89-3D1F-4E61-BB18-5511E1DC150F/Rage Masters.app/Rage MastersIdentifier: Rage MastersVersion: ??? (???)Code Type: ARM (Native)Parent Process: launchd [1]Date/Time: 2012-11-03 13:38:45.762 -0400OS Version: iOS 6.0 (10A403)Report Version: 104Exception Type: EXC_CRASH (SIGABRT)Exception Codes: 0x0000000000000000, 0x0000000000000000Crashed Thread: 0Last Exception Backtrace:0 CoreFoundation 0x36bff29e __exceptionPreprocess + 1581 libobjc.A.dylib 0x34f0f97a objc_exception_throw + 262 CoreFoundation 0x36bff158 +[NSException raise:format:arguments:] + 963 Foundation 0x346812aa -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 864 UIKit 0x37f04b7e -[UITableView(_UITableViewPrivate) _endCellAnimationsWithContext:] + 76905 UIKit 0x3803a4a2 -[UITableView deleteRowsAtIndexPaths:withRowAnimation:] + 226 Rage Masters 0x000fd9ca -[RMBookmarksViewController tableView:commitEditingStyle:forRowAtIndexPath:] (RMBookmarksViewController.m:68)7 UIKit 0x3809a5d4 -[UITableView(UITableViewInternal) animateDeletionOfRowWithCell:] + 808 UIKit 0x37fbb0a8 -[UIApplication sendAction:to:from:forEvent:] + 689 UIKit 0x37fbb05a -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 2610 UIKit 0x37fbb038 -[UIControl sendAction:to:forEvent:] + 4011 UIKit 0x37fba8ee -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 49812 UIKit 0x37fbb0a8 -[UIApplication sendAction:to:from:forEvent:] + 6813 UIKit 0x37fbb05a -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 2614 UIKit 0x37fbb038 -[UIControl sendAction:to:forEvent:] + 4015 UIKit 0x37fba8ee -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 49816 UIKit 0x37fbade4 -[UIControl touchesEnded:withEvent:] + 48417 UIKit 0x37ee35f4 -[UIWindow _sendTouchesForEvent:] + 52018 UIKit 0x37ed0804 -[UIApplication sendEvent:] + 37619 UIKit 0x37ed011e _UIApplicationHandleEvent + 615020 GraphicsServices 0x3708359e _PurpleEventCallback + 58621 GraphicsServices 0x370831ce PurpleEventCallback + 3022 CoreFoundation 0x36bd416e __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 3023 CoreFoundation 0x36bd4112 __CFRunLoopDoSource1 + 13424 CoreFoundation 0x36bd2f94 __CFRunLoopRun + 138025 CoreFoundation 0x36b45eb8 CFRunLoopRunSpecific + 35226 CoreFoundation 0x36b45d44 CFRunLoopRunInMode + 10027 GraphicsServices 0x370822e6 GSEventRunModal + 7028 UIKit 0x37f242fc UIApplicationMain + 111629 Rage Masters 0x000fb004 main (main.m:16)30 libdyld.dylib 0x3b630b1c start + 0
这看起来跟前面那个崩溃日志很像。是另一个SIGABRT 异常。 你可能想知道是否是相同的问题:发送信息到一个没有实现相应方法的对象?
6 Rage Masters 0x00088c66 -[RMBookmarksViewController tableView:commitEditingStyle:forRowAtIndexPath:] (RMBookmarksViewController.m:68)
这是UITableViewDataSource 的一个方法. 呵呵?! 毫无疑问苹果已经实现了该方法 —— 你可以重载它, 但不像是还没有实现。而且,这是个可选的委派方法。 所以问题不是调用了一个没有实现的方法。
3 Foundation 0x346812aa -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 864 UIKit 0x37f04b7e -[UITableView(_UITableViewPrivate) _endCellAnimationsWithContext:] + 76905 UIKit 0x3803a4a2 -[UITableView deleteRowsAtIndexPaths:withRowAnimation:] + 22
帧 5, UITableView调用了它自己的另一个方法 deleteRowsAtIndexPaths:withRowAnimation: 然后是看起来像苹果内部方法的_endCellAnimationsWithContext: 被调用。然后Foundation framework发生异常handleFailureInMethod:object:file:lineNumber:description:.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];}
发现问题了吗? 给你点时间,仔细看一下。
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { RMMaster *masterToDelete = [bookmarks objectAtIndex:indexPath.row]; [bookmarks removeObject:masterToDelete]; [[RMBookmarks sharedBookmarks] unbookmarkMaster:masterToDelete]; [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];}
搞定了!走起,讨厌的 bug!!
Incident Identifier: 081E58F5-95A8-404D-947B-5E104B6BC1B1CrashReporter Key: 5a56599d836c4f867f6eec76afee451bf9ae5f31Hardware Model: iPhone4,1OS Version: iPhone OS 6.0 (10A403)Kernel Version: Darwin Kernel Version 13.0.0: Sun Aug 19 00:28:05 PDT 2012; root:xnu-2107.2.33~4/RELEASE_ARM_S5L8940XDate: 2012-11-03 13:39:59 -0400Time since snapshot: 4353 msFree pages: 968Active pages: 7778Inactive pages: 4005Throttled pages: 92319Purgeable pages: 0Wired pages: 23347Largest process: Rage MastersProcesses Name <UUID> rpages recent_max [reason] (state) lsd <6a9f5b5f36b23fc78f87b6d8f1f49a9d> 331 331 [vm] (daemon) (idle) afcd <b0aff2e7952e34a9882fec81a8dcdbb2> 141 141 [vm] (daemon) (idle) itunesstored <4e0cd9f873de3435b4119c48b2d6d13d> 1761 1761 [vm] (daemon) (idle)softwareupdatese <2bc4b5ae016431c98d3b34f81027d0ae> 311 311 [vm] (daemon) (idle) Amazon <4600481f07ec3e59a925319b7f67ba14> 2951 2951 [vm] (suspended) accountsd <ac0fce15c1a2350d951efc498d521ac7> 519 519 [vm] (daemon) (idle)coresymbolicatio <edba67001f76313b992056c712153b4b> 126 126 [vm] (daemon) (idle) Skype <504cf2fe60cb3cdea8273e74df09836b> 3187 3187 [vm] (background) MobileMail <bff817c61ce33c85a43ea9a6c98c29f5> 14927 14927 [vm] (continuous) MobileSMS <46778de076363d67aeea207464cfc581> 2134 2134 [vm] (background) MobilePhone <3fca241f2a193d0fb8264218d296ea41> 2689 2689 [vm] (continuous) librariand <c9a9be81aa9632f0a913ce79b911f27e> 317 317 [vm] (daemon) kbd <3e7136ddcefc3d77a01499db593466cd> 616 616 [vm] (daemon) tccd <eb5ddcf533663f8d987d67cae6a4c4ea> 224 224 [vm] (daemon) Rage Masters <90b45d6281e934209c5b06cf7dc4d492> 28591 28591 [vm] (frontmost) (resume) ptpd <04a56fce67053c57a7979aeea8e5a7ea> 879 879 (daemon) iaptransportd <f784f30dc09d32078d87b450e8113ef6> 230 230 (daemon) locationd <892cd1c9ffa43c99a82dba197be5f09e> 1641 1641 (daemon) syslogd <cbef142fa0a839f0885afb693fb169c3> 237 237 (daemon) mediaserverd <80657170daca32c9b8f3a6b1faac43a2> 4869 4869 (daemon) dataaccessd <2a3f6a518f3f3646bf35eddd36f25005> 1786 1786 (daemon) aosnotifyd <d4d14f2914c3343796e447cfef3e6542> 549 549 (daemon) wifid <9472b090746237998cdbb9b34f090d0c> 455 455 (daemon) SpringBoard <27372aae101f3bbc87804edc10314af3> 18749 18749 backboardd <5037235f295b33eda98eb5c72c098858> 5801 5801 (daemon) UserEventAgent <6edfd8d8dba23187b05772dcdfc94f90> 601 601 (daemon) mediaremoted <4ff39c50c684302492e396ace813cb25> 293 293 (daemon) pasteboardd <8a4279b78e4a321f84a076a711dc1c51> 176 176 (daemon)springboardservi <ff6f64b3a21a39c9a1793321eefa5304> 0 0 (daemon) syslog_relay <45e9844605d737a08368b5215bb54426> 0 0 (daemon) DTMobileIS <23303ca402aa3705870b01a9047854ea> 0 0 (daemon)notification_pro <845b7beebc8538ca9ceef731031983b7> 169 169 (daemon) syslog_relay <45e9844605d737a08368b5215bb54426> 0 0 (daemon) ubd <74dc476d1785300e9fcda555fcb8d774> 976 976 (daemon) twitterd <4b4946378a9c397d8250965d17055b8e> 730 730 (daemon) configd <4245d73a9e96360399452cf6b8671844> 809 809 (daemon) absinthed.N94 <7f4164c844fa340caa940b863c901aa9> 99 99 (daemon)filecoordination <fbab576f37a63b56a1039153fc1aa7d8> 226 226 (daemon) distnoted <a89af76ec8633ac2bbe99bc2b7964bb0> 137 137 (daemon) apsd <94d8051dd5f5362f82d775bc279ae608> 373 373 (daemon) networkd <0032f46009f53a6c80973fe153d1a588> 219 219 (daemon) aggregated <8c3c991dc4153bc38aee1e841864d088> 112 112 (daemon) BTServer <c92fbd7488e63be99ec9dbd05824f5e5> 522 522 (daemon) fairplayd.N94 <7bd896bd00783a48906090d05cf1c86a> 210 210 (daemon) fseventsd <996cc4ca03793184aea8d781b55bce08> 384 384 (daemon) imagent <1e68080947be352590ce96b7a1d07b2f> 586 586 (daemon) mDNSResponder <3e557693f3073697a58da6d27a827d97> 295 295 (daemon) lockdownd <ba1358c7a8003f1b91af7d5f58dd5bbe> 389 389 (daemon) powerd <2d2ffed5e69638aeba1b92ef124ed861> 174 174 (daemon) CommCenter <1f425e1e897d32e8864fdd8eeaa803a8> 2212 2212 (daemon) notifyd <51c0e03da8a93ac8a595442fcaac531f> 211 211 (daemon) ReportCrash <8c32f231b2ed360bb151b2563bcaa363> 337 337 (daemon)
这日志跟我们前面见到的相差很多。
#import "RMLollipopLicker.h"#define COUNT 20@interface RMLollipopLicker ()@property (weak, nonatomic) IBOutlet UIProgressView *progressView;@property (weak, nonatomic) IBOutlet UILabel *label;@property (weak, nonatomic) IBOutlet UILabel *lickedTimeLabel;@end@implementation RMLollipopLicker { NSOperationQueue *queue; NSMutableArray *lollipops;}#pragma mark - Life cycle- (void)viewDidLoad { [super viewDidLoad]; self.progressView.progress = 0.0; self.label.text = [NSString stringWithFormat:@"Tap on run and I'll lick a lollipop %d times!", COUNT]; self.lickedTimeLabel.text = @""; lollipops = [[NSMutableArray alloc] init]; queue = [[NSOperationQueue alloc] init];}- (void)lickLollipop { NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"Lollipop" withExtension:@"plist"]; NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfURL:fileURL]; NSString *lollipop = [dictionary objectForKey:@"Lollipop"]; [lollipops addObject:lollipop];}#pragma mark - IBActions- (IBAction)doneButtonPressed:(id)sender { [self dismissViewControllerAnimated:YES completion:nil];}- (IBAction)runButtonPressed:(id)sender { [sender setEnabled:NO]; [queue addOperationWithBlock:^{ for (NSInteger i = 0 ; i = COUNT) { self.label.text = [NSString stringWithFormat:@"Tap on run and I'll lick a lollipop %d times!", COUNT]; self.progressView.progress = 0.0; [sender setEnabled:YES]; } }];}}];}@end
当用户点击运行按钮, 应用开始一个背景线程,调用 lickLollipop 方法若干次,然后更新界面反映吃棒棒糖的数量。 lickLollipop 方法从属性列表文件(PLIST)文件读取一个长字符串,然后添加到数组上。这些数据并不重要, 能在不影响用户体验的前提下重新创建。
-(void)didReceiveMemoryWarning { [lollipops removeAllObjects]; [super didReceiveMemoryWarning];}
下一步?
总结一下本文,有以下几个要点:
以上文章大部分转自他处。转载请注明 编程小翁@博客园,邮件zilin_weng@163.com,微信Jilon,联系请注明“博客园”。欢迎各位与我在C/C++/Objective-C/机器视觉等领域展开交流!