iPhone3开发基础教程中部分有用代码片段(1)

《beginning iphone3 development exploring the iphone SDK》一书中有很多基础的代码片段 ,由这些最原始的代码片段组成了我们的复杂的iphone应用程序,所以这里就借用一网友的总结,一大家一起分享。

  1. stringWithFormat 用法:

view plaincopy to clipboardprint?
[NSString stringWithFormat:@"Hight: %d°%@   Low: %d°%@", [Temp],@"C",[lTemp],@"C"]; 
 [NSString stringWithFormat:@"Hight: %d°%@   Low: %d°%@", [Temp],@"C",[lTemp],@"C"];

2. NSDate 用法:

         NSDate  *today;

view plaincopy to clipboardprint?
NSDate *tomorrow;  
  today = [NSDate date];  
  tomorrow = [NSDate dateWithTimeInterval:(i*24*60*60) sinceDate:today]; //可能有更好的 
  NSDate *tomorrow;
    today = [NSDate date];
    tomorrow = [NSDate dateWithTimeInterval:(i*24*60*60) sinceDate:today]; //可能有更好的

Date format用法:

view plaincopy to clipboardprint?
-(NSString *) getDay:(NSDate *) d {  
   NSString *s ;  
   NSDateFormatter *format = [[NSDateFormatter alloc] init];  
   [format setDateFormat:@"YYYY/MM/dd hh:mm:ss"];  
   s = [format stringFromDate:d];  
   [format release];  
   return s;  
 -(NSString *) getDay:(NSDate *) d {
    NSString *s ;
    NSDateFormatter *format = [[NSDateFormatter alloc] init];
    [format setDateFormat:@"YYYY/MM/dd hh:mm:ss"];
    s = [format stringFromDate:d];
    [format release];
    return s;
}

    各地时区获取:

view plaincopy to clipboardprint?
NSDate *nowDate = [NSDate new];  
   NSDateFormatter *formatter    =  [[NSDateFormatter alloc] init];  
   [formatter    setDateFormat:@"yyyy/MM/dd HH:mm:ss"];  
   //    根据时区名字获取当前时间,如果该时区不存在,默认获取系统当前时区的时间  
   //    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Europe/Andorra"];      
   //    [formatter setTimeZone:timeZone];  
   //获取所有的时区名字  
   NSArray *array = [NSTimeZone knownTimeZoneNames];  
   //    NSLog(@"array:%@",array);  
   //for循环  
   //    for(int i=0;i<[array count];i++)  
   //    {  
   //        NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:[array objectAtIndex:i]];  
   //        [formatter setTimeZone:timeZone];  
   //        NSString *locationTime = [formatter stringFromDate:nowDate];  
   //        NSLog(@"时区名字:%@   : 时区当前时间: %@",[array objectAtIndex:i],locationTime);  
   //        //NSLog(@"timezone name is:%@",[array objectAtIndex:i]);  
   //    }      
   //快速枚举法  
   for(NSString *timeZoneName in array){  
       [formatter setTimeZone:[NSTimeZone timeZoneWithName:timeZoneName]];  
       NSLog(@"%@,%@",timeZoneName,[formatter stringFromDate:nowDate]);  
   }  
     
   [formatter release];  
   [nowDate release]; 
 NSDate *nowDate = [NSDate new];
    NSDateFormatter *formatter    =  [[NSDateFormatter alloc] init];
    [formatter    setDateFormat:@"yyyy/MM/dd HH:mm:ss"];
    //    根据时区名字获取当前时间,如果该时区不存在,默认获取系统当前时区的时间
    //    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Europe/Andorra"];   
    //    [formatter setTimeZone:timeZone];
    //获取所有的时区名字
    NSArray *array = [NSTimeZone knownTimeZoneNames];
    //    NSLog(@"array:%@",array);
    //for循环
    //    for(int i=0;i<[array count];i++)
    //    {
    //        NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:[array objectAtIndex:i]];
    //        [formatter setTimeZone:timeZone];
    //        NSString *locationTime = [formatter stringFromDate:nowDate];
    //        NSLog(@"时区名字:%@   : 时区当前时间: %@",[array objectAtIndex:i],locationTime);
    //        //NSLog(@"timezone name is:%@",[array objectAtIndex:i]);
    //    }   
    //快速枚举法
    for(NSString *timeZoneName in array){
        [formatter setTimeZone:[NSTimeZone timeZoneWithName:timeZoneName]];
        NSLog(@"%@,%@",timeZoneName,[formatter stringFromDate:nowDate]);
    }
   
    [formatter release];
    [nowDate release];

     3. NSCalendar用法:

view plaincopy to clipboardprint?
 -(NSString *) getWeek:(NSDate *) d {  
      
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];  
    unsigned units = NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit | NSWeekdayCalendarUnit;  
    NSDateComponents *components = [calendar components:units fromDate:d];  
    [calendar release];  
      
    switch ([components weekday]) {  
        case 2:  
            return @"Monday";  
            break;  
        case 3:  
            return @"Tuesday";  
            break;  
        case 4:  
            return @"Wednesday";  
            break;  
        case 5:  
           return @"Thursday";  
            break;  
        case 6:  
            return  @"Friday";  
            break;  
        case 7:  
            return  @"Saturday";  
            break;  
        case 1:  
            return @"Sunday";  
            break;  
        default:  
            return @"No Week";  
            break;  
    }  
    // 用components,我们可以读取其他更多的数据。  
      
} 
 -(NSString *) getWeek:(NSDate *) d {
   
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    unsigned units = NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit | NSWeekdayCalendarUnit;
    NSDateComponents *components = [calendar components:units fromDate:d];
    [calendar release];
   
    switch ([components weekday]) {
        case 2:
            return @"Monday";
            break;
        case 3:
            return @"Tuesday";
            break;
        case 4:
            return @"Wednesday";
            break;
        case 5:
           return @"Thursday";
            break;
        case 6:
            return  @"Friday";
            break;
        case 7:
            return  @"Saturday";
            break;
        case 1:
            return @"Sunday";
            break;
        default:
            return @"No Week";
            break;
    }
    // 用components,我们可以读取其他更多的数据。
   
}

 4. 用Get方式读取网络数据:

view plaincopy to clipboardprint?
// 将网络数读取为字符串  
- (NSString *) getDataByURL:(NSString *) url {  
    return [[NSString alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]] encoding:NSUTF8StringEncoding];  
}  
//读取网络图片  
- (UIImage *) getImageByURL:(NSString *) url {  
    return [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]];  
} 
// 将网络数读取为字符串
- (NSString *) getDataByURL:(NSString *) url {
    return [[NSString alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]] encoding:NSUTF8StringEncoding];
}
//读取网络图片
- (UIImage *) getImageByURL:(NSString *) url {
    return [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]];
}

  5. 多线程NSThread用法 :

view plaincopy to clipboardprint?
[NSThread detachNewThreadSelector:@selector(scheduleTask) toTarget:self withObject:nil];  
-(void) scheduleTask {  
    //create a pool   
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];  
    //release the pool;  
    [pool release];  
}  
//如果有参数,则这么使用:  
[NSThread detachNewThreadSelector:@selector(scheduleTask:) toTarget:self withObject:[NSDate date]];  
-(void) scheduleTask:(NSDate *) mdate {  
    //create a pool   
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];  
    //release the pool;  
    [pool release];  
}  
//注意selector里有冒号。  
    //在线程里运行主线程里的方法   
   UIApplication* app = [UIApplication sharedApplication];  
    [app performSelectorOnMainThread:@selector(moveToMain) withObject:nil waitUntilDone:FALSE]; 
[NSThread detachNewThreadSelector:@selector(scheduleTask) toTarget:self withObject:nil];
-(void) scheduleTask {
    //create a pool
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    //release the pool;
    [pool release];
}
//如果有参数,则这么使用:
[NSThread detachNewThreadSelector:@selector(scheduleTask:) toTarget:self withObject:[NSDate date]];
-(void) scheduleTask:(NSDate *) mdate {
    //create a pool
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    //release the pool;
    [pool release];
}
//注意selector里有冒号。
    //在线程里运行主线程里的方法
   UIApplication* app = [UIApplication sharedApplication];
    [app performSelectorOnMainThread:@selector(moveToMain) withObject:nil waitUntilDone:FALSE];

 


      6. 定时器NSTimer用法:

view plaincopy to clipboardprint?
 // 一个可以自动关闭的Alert窗口  
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil   
                                                    message:[@"一个可以自动关闭的Alert窗口" 
                                                   delegate:nil   
                                          cancelButtonTitle:nil //NSLocalizedString(@"OK", @"OK")   //取消任何按钮  
                                          otherButtonTitles:nil];  
    //[alert setBounds:CGRectMake(alert.bounds.origin.x, alert.bounds.origin.y, alert.bounds.size.width, alert.bounds.size.height+30.0)];  
    [alert show];  
      
    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];  
      
    // Adjust the indicator so it is up a few pixels from the bottom of the alert      
    indicator.center = CGPointMake(alert.bounds.size.width/2,  alert.bounds.size.height-40.0);  
    [indicator startAnimating];  
    [alert insertSubview:indicator atIndex:0];  
    [indicator release];  
      
    [NSTimer scheduledTimerWithTimeInterval:3.0f  
                                     target:self  
                                   selector:@selector(dismissAlert:)  
                                   userInfo:[NSDictionary dictionaryWithObjectsAndKeys:alert, @"alert", @"testing ", @"key" ,nil]  //如果不用传递参数,那么可以将此项设置为nil.  
                                    repeats:NO];  
    NSLog(@"release alert");  
    [alert release];  
-(void) dismissAlert:(NSTimer *)timer{  
      
    NSLog(@"release timer");  
    NSLog([[timer userInfo]  objectForKey:@"key"]);  
      
    UIAlertView *alert = [[timer userInfo]  objectForKey:@"alert"];  
    [alert dismissWithClickedButtonIndex:0 animated:YES];  
     
} 
 // 一个可以自动关闭的Alert窗口
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil
                                                    message:[@"一个可以自动关闭的Alert窗口"
                                                   delegate:nil
                                          cancelButtonTitle:nil //NSLocalizedString(@"OK", @"OK")   //取消任何按钮
                                          otherButtonTitles:nil];
    //[alert setBounds:CGRectMake(alert.bounds.origin.x, alert.bounds.origin.y, alert.bounds.size.width, alert.bounds.size.height+30.0)];
    [alert show];
   
    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
   
    // Adjust the indicator so it is up a few pixels from the bottom of the alert   
    indicator.center = CGPointMake(alert.bounds.size.width/2,  alert.bounds.size.height-40.0);
    [indicator startAnimating];
    [alert insertSubview:indicator atIndex:0];
    [indicator release];
   
    [NSTimer scheduledTimerWithTimeInterval:3.0f
                                     target:self
                                   selector:@selector(dismissAlert:)
                                   userInfo:[NSDictionary dictionaryWithObjectsAndKeys:alert, @"alert", @"testing ", @"key" ,nil]  //如果不用传递参数,那么可以将此项设置为nil.
                                    repeats:NO];
    NSLog(@"release alert");
    [alert release];
-(void) dismissAlert:(NSTimer *)timer{
   
    NSLog(@"release timer");
    NSLog([[timer userInfo]  objectForKey:@"key"]);
   
    UIAlertView *alert = [[timer userInfo]  objectForKey:@"alert"];
    [alert dismissWithClickedButtonIndex:0 animated:YES];
  
}
 

 7. 用户缺省值NSUserDefaults读取:

view plaincopy to clipboardprint?
//得到用户缺省值  
    NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];  
      
    //在缺省值中找到AppleLanguages, 返回值是一个数组  
    NSArray* languages = [defs objectForKey:@"AppleLanguages"];  
    NSLog(@"all language语言 is %@", languages);  
      
    //在得到的数组中的第一个项就是用户的首选语言了  
    NSLog(@"首选语言 is %@",[languages objectAtIndex:0]);    
    //get the language & country code  
    NSLocale *currentLocale = [NSLocale currentLocale];  
      
    NSLog(@"Language Code is %@", [currentLocale objectForKey:NSLocaleLanguageCode]);      
    NSLog(@"Country Code is %@", [currentLocale objectForKey:NSLocaleCountryCode]);    
//得到用户缺省值
    NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
   
    //在缺省值中找到AppleLanguages, 返回值是一个数组
    NSArray* languages = [defs objectForKey:@"AppleLanguages"];
    NSLog(@"all language语言 is %@", languages);
   
    //在得到的数组中的第一个项就是用户的首选语言了
    NSLog(@"首选语言 is %@",[languages objectAtIndex:0]); 
    //get the language & country code
    NSLocale *currentLocale = [NSLocale currentLocale];
   
    NSLog(@"Language Code is %@", [currentLocale objectForKey:NSLocaleLanguageCode]);   
    NSLog(@"Country Code is %@", [currentLocale objectForKey:NSLocaleCountryCode]);   

  8. View之间切换的动态效果设置:

view plaincopy to clipboardprint?
SettingsController *settings = [[SettingsController alloc]initWithNibName:@"SettingsView" bundle:nil];  
settings.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;  //水平翻转  
[self presentModalViewController:settings animated:YES];  
[settings release]; 
    SettingsController *settings = [[SettingsController alloc]initWithNibName:@"SettingsView" bundle:nil];
    settings.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;  //水平翻转
    [self presentModalViewController:settings animated:YES];
    [settings release];

9.NSScrollView 滑动用法:

view plaincopy to clipboardprint?
-(void) scrollViewDidScroll:(UIScrollView *)scrollView{  
    NSLog(@"正在滑动中...");  
}  
//用户直接滑动NSScrollView,可以看到滑动条  
-(void) scrollViewDidEndDecelerating:(UIScrollView *)scrollView {  
}  
// 通过其他控件触发NSScrollView滑动,看不到滑动条  
- (void) scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {  
} 
-(void) scrollViewDidScroll:(UIScrollView *)scrollView{
    NSLog(@"正在滑动中...");
}
//用户直接滑动NSScrollView,可以看到滑动条
-(void) scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
}
// 通过其他控件触发NSScrollView滑动,看不到滑动条
- (void) scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
}

    10. 读取全局的Delegate:

view plaincopy to clipboardprint?
KiloNetAppDelegate *appdelegate = (KiloNetAppDelegate *)[[UIApplication sharedApplication] delegate]; 
KiloNetAppDelegate *appdelegate = (KiloNetAppDelegate *)[[UIApplication sharedApplication] delegate];

 11.键盘处理系列

view plaincopy to clipboardprint?
//set the UIKeyboard to switch to a different text field when you press return  
//switch textField to the name of your textfield  
[textField becomeFirstResponder]; 
//set the UIKeyboard to switch to a different text field when you press return
//switch textField to the name of your textfield
[textField becomeFirstResponder];

12. 半透明层的实现:

view plaincopy to clipboardprint?
+(void)showWaiting:(UIView *)parent {  
    int width = 32, height = 32;  
      
    CGRect frame = [parent frame]; //[[UIScreen mainScreen] applicationFrame];  
    int x = frame.size.width;  
    int y = frame.size.height;  
      
    frame = CGRectMake((x - width) / 2, (y - height) / 2, width, height);  
    UIActivityIndicatorView* progressInd = [[UIActivityIndicatorView alloc] initWithFrame:frame];  
    [progressInd startAnimating];  
    progressInd.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;  
      
      
//    frame = CGRectMake((x - 140)/2, (y - height) / 2 + height, 140, 30);  
//    UILabel *waitingLable = [[UILabel alloc] initWithFrame:frame];  
//    waitingLable.text = @"Proccesing...";  
//    waitingLable.textColor = [UIColor whiteColor];  
//    waitingLable.font = [UIFont systemFontOfSize:15];  
//    waitingLable.backgroundColor = [UIColor clearColor];  
      
    frame = [parent frame];  
    UIView *theView = [[UIView alloc] initWithFrame:frame];  
    theView.backgroundColor = [UIColor blackColor];  
    theView.alpha = 0.8;  
      
    [theView addSubview:progressInd];  
//  [theView addSubview:waitingLable];  
      
    [progressInd release];  
//    [waitingLable release];  
      
    [theView setTag:9999];  
    [parent addSubview:theView];  
    [theView release];  
}  
+(void)hideWaiting:(UIView *)parent {  
    [[parent viewWithTag:9999] removeFromSuperview];  
} 
+(void)showWaiting:(UIView *)parent {
    int width = 32, height = 32;
   
    CGRect frame = [parent frame]; //[[UIScreen mainScreen] applicationFrame];
    int x = frame.size.width;
    int y = frame.size.height;
   
    frame = CGRectMake((x - width) / 2, (y - height) / 2, width, height);
    UIActivityIndicatorView* progressInd = [[UIActivityIndicatorView alloc] initWithFrame:frame];
    [progressInd startAnimating];
    progressInd.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
   
   
//    frame = CGRectMake((x - 140)/2, (y - height) / 2 + height, 140, 30);
//    UILabel *waitingLable = [[UILabel alloc] initWithFrame:frame];
//    waitingLable.text = @"Proccesing...";
//    waitingLable.textColor = [UIColor whiteColor];
//    waitingLable.font = [UIFont systemFontOfSize:15];
//    waitingLable.backgroundColor = [UIColor clearColor];
   
    frame = [parent frame];
    UIView *theView = [[UIView alloc] initWithFrame:frame];
    theView.backgroundColor = [UIColor blackColor];
    theView.alpha = 0.8;
   
    [theView addSubview:progressInd];
//  [theView addSubview:waitingLable];
   
    [progressInd release];
//    [waitingLable release];
   
    [theView setTag:9999];
    [parent addSubview:theView];
    [theView release];
}
+(void)hideWaiting:(UIView *)parent {
    [[parent viewWithTag:9999] removeFromSuperview];
}

 13. 设置View的圆角:

view plaincopy to clipboardprint?
 // 首先应用  #import <QuartzCore/QuartzCore.h>  
view.layer.cornerRadius = 10;  
view.layer.masksToBounds = YES; 
 // 首先应用  #import <QuartzCore/QuartzCore.h>
view.layer.cornerRadius = 10;
view.layer.masksToBounds = YES;

14.随机数:

view plaincopy to clipboardprint?
srandom(time(NULL)); //随机数种子  
id d = random(); // 随机数 
srandom(time(NULL)); //随机数种子
id d = random(); // 随机数

15.视频播放:

view plaincopy to clipboardprint?
MPMoviePlayerController *moviePlayer;  
   moviePlayer = [[MPMoviePlayerController alloc]  
                  initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Movie" ofType:@"m4v"]]];  
   //初始化视频播放器对象,并传入被播放文件的地址  
   moviePlayer.movieControlMode = MPMovieControlModeDefault;  
   [moviePlayer play];  
   //此处有内存溢出 
 MPMoviePlayerController *moviePlayer;
    moviePlayer = [[MPMoviePlayerController alloc]
                   initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Movie" ofType:@"m4v"]]];
    //初始化视频播放器对象,并传入被播放文件的地址
    moviePlayer.movieControlMode = MPMovieControlModeDefault;
    [moviePlayer play];
    //此处有内存溢出

16. 3.  启动界面显示:

iPhone软件启动后的第一屏图片是非常重要的往往就是loading载入中的意思。设置它说来也简单,但是却无比重要

只需要在resource里面将你希望设置的图片更名为Default.png,这个图片就可以成为iPhone载入的缺省图片

17.iPhone的系统目录:

view plaincopy to clipboardprint?
//得到Document目录:  
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  
NSString *documentsDirectory = [paths objectAtIndex:0];  
//得到temp临时目录:  
NSString *tempPath = NSTemporaryDirectory();  
//得到目录上的文件地址:  
NSString *文件地址 = [目录地址 stringByAppendingPathComponent:@"文件名.扩展名"]; 
//得到Document目录:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
//得到temp临时目录:
NSString *tempPath = NSTemporaryDirectory();
//得到目录上的文件地址:
NSString *文件地址 = [目录地址 stringByAppendingPathComponent:@"文件名.扩展名"];

18.状态栏显示Indicator:

view plaincopy to clipboardprint?
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;  
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
 

 

本文来自优快云博客,转载请标明出处:http://blog.youkuaiyun.com/ipromiseu/archive/2010/08/22/5830398.aspx

 

Windows游戏玩家必看:用Process Lasso优化CPU优先级和核心绑定,告别卡顿 本文为Windows游戏玩家详细介绍了如何使用Process Lasso优化系统性能。通过设置CPU优先级和核心绑定,可以智能管理进程资源,确保游戏获得最高调度权限,有效减少因后台程序干扰或Windows调度机制不完善导致的卡顿与帧数波动,从而提升游戏流畅度与稳定性。 阅读详情

相关推荐

Python 音频: sounddevice 使用 左声道/右声道/立体声 --- 播放,录音

# coding: utf8 """ Python 音频: 使用 sounddevice 操作声卡的 左声道, 右声道, 立体声 仅限 MME, Windows DirectSound, Windows WASAPI, Windows WDM-KS 等支持双声道的驱动类型 """ import os import sounddevice as sd import soundfile mapping_left_ch = 1 # 左声道为 1 mapping_right_ch

weixin_42019925的博客 4926

iphone 代码片段2

http://www.cnblogs.com/likwo/archive/2010/09/19/1830788.html   Iphone代码片段导航  Iphone开发代码片段1 Iphone开发代码片段2  Iphone开发代码片段3  1. 如果您想在应用里添加提示功能,比如让 iPhone 机身震动,可以使用下面这行代码: AudioS

zhangjie1989的专栏 413

NRF52832调试方法1——HardFault_Handler问题定位

一、遇到问题 keil debug模式下,直接点击全速运行(Run)发现程序卡死,点击stop按钮后,停到了HardFault_Handler位置,如下图所示。 此时使用navigate backwards(蓝色左箭头)是无效的,找不到程序卡在哪里。 二、解决办法 此时首先观察register窗口 若Stack为MSP,则复制R13(SP)的值到memory观察窗的地址搜索栏。每一行显示连续的28个地址上的存储信息,每个地址上存有一个字节。 从第21个位置起的连续四个字节是LR的值,

小梁的博客 3650

Iphone开发代码片段3

http://www.cnblogs.com/likwo/archive/2011/03/15/1984761.html  Iphone代码片段导航  Iphone开发代码片段1 Iphone开发代码片段2  Iphone开发代码片段3  1.给UITableViewController添加ToolBar。  self.navigationContr

zhangjie1989的专栏 1351

Allegro 16.6 高级技巧实战:用Region规则和动态间距搞定高密度连接器布局布线

本文深入探讨了Allegro 16.6在高密度连接器布局布线中的高级技巧,重点介绍了Region规则和动态间距属性的应用。通过局部规则覆盖和分层控制,解决0.5mm以下引脚间距的布线难题,提升PCB设计效率和质量。

weixin_30352645的博客 439

SAP ABAP实战:如何用CVI_EI_INBOUND_MAIN批量更新BP邮箱(附完整代码)

本文深入解析了SAP ABAP中CVI_EI_INBOUND_MAIN函数在业务伙伴(BP)邮箱地址批量维护场景下的应用。通过详细讲解数据结构构建、关键参数(如任务参数'5')配置及完整代码示例,为开发者提供了一套高效、稳定的批量更新解决方案,并分享了性能优化与错误处理的最佳实践。

weixin_29228781的博客 77

Iphone代码片段导航

http://www.cnblogs.com/likwo/archive/2011/03/15/1984761.html Iphone代码片段导航  Iphone开发代码片段1 Iphone开发代码片段2  Iphone开发代码片段3  1.给UITableViewController添加ToolBar。  self.navigationController

zeng11088的专栏 820

太阳敏感器:卫星姿态控制的“指南针

在卫星姿态控制系统中,太阳敏感器(Sun Sensor) 是至关重要的光学姿态敏感器之一。它通过探测太阳光的方向,为卫星提供关键的姿态参考信息,确保卫星能够正确调整自身方位,维持稳定的对日定向,保障能源供应和任务执行。

ScilogyHunter的博客 1730

Iphone开发代码片段1

 Iphone代码片段导航   Iphone开发代码片段1 Iphone开发代码片段2  Iphone开发代码片段3   UItableView  UITextField    NSString *text = ((UITextField *)cell.accessoryView).text; However, you must be careful about sett...

weixin_33972649的博客 106

【Tiny_CD】Tiny_CD变化检测网络详解(含python代码)

tiny-cd网络详解,含论文下载、代码下载地址。

向上生长的程序媛的博客 2161

深入理解鸿蒙输入子系统驱动:HDI接口、HAL层与内核驱动的协同机制

/ 扫描输入设备// 打开指定输入设备// 关闭指定输入设备// 获取指定设备信息// 获取所有设备列表鸿蒙输入子系统驱动采用分层架构设计,通过HDI接口层实现硬件抽象,HAL层提供统一的事件处理机制,用户空间驱动层负责设备管理和事件分发。整个系统支持多种输入设备类型,包括触摸屏、按键、鼠标、键盘等,并提供了完整的HID设备支持。分层架构:清晰的层次划分,便于维护和扩展事件驱动:基于epoll的高效事件处理机制设备管理:完善的设备生命周期管理HID支持。

m0_67505153的博客 212

Iphone代码片段 收集

Iphone代码片段导航 Iphone开发代码片段1 Iphone开发代码片段2 Iphone开发代码片段3 1.给UITableViewController添加ToolBar。 self.navigationController.toolbarHidden = NO; //默认是隐藏的。 //添加MessageToolBar ,messageToolB...

mmdev 116

AgentScope Java 2.0 最佳实践:9 个完整示例手把手带你开发 Java‑Agent

本文基于9 个完整示例,深入剖析从基础对话(BasicChatExample)、工具调用(@Tool 注解)、结构化输出(POJO Schema)、ToolGroup 自主管理、MCP 外部工具集成、Hook 生命周期监控、Spring Boot SSE 流式 Web、JsonSession 会话持久化到中断恢复的全链路实战教程。

program哲学 1637

Iphone代码片段

Iphone代码片段导航 Iphone开发代码片段1 Iphone开发代码片段2 Iphone开发代码片段3 1.给UITableViewController添加ToolBar。 self.navigationController.toolbarHidden = NO; //默认是隐藏的。 //添加MessageToolBar ,messageToolB...

85

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

上一篇: Glassfish-v2和apache2.2.6的整合
下一篇: iPhone 突然发现,setting配置文件中的DefaultValue可能拿不了值
xinlanzero
博客等级 码龄25年 10粉丝 132原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值