错误检查和代码重查Troubleshooting and Reviewing the Code

如果你的应用不能正确运行,尝试问题-解决路径。如果你的应用还是没有运行,将你的代码与本章最后的列表对照一下。If you are having trouble getting your app to work correctly, try the problem-solving approaches described in this chapter. If your app still isn’t working as it should, compare your code with the listings shown at the end of this chapter.

代码和编译警告Code and Compiler Warnings

你的代码编译后应该没有警告。如果还是有警告,它的建议是你处理它们像处理错误一样。因为OC是一个灵活的语言,有时编译器通常会提示警告。Your code should compile without any warnings. If you do receive warnings, it’s recommended that you treat them as very likely to be errors. Because Objective-C is a very flexible language, sometimes the most you get from the compiler is a warning.

Check the Storyboard File

作为一个开发者,如果不能运行,本能是可能查看你的源代码找错误。但是当你用 Cocoa Touch时,会添加另一个尺寸。你的大部分应用配置可能是用 storyboard 拖拽实现的。例如,如果你没有正确连接,你的应用不会如期运行。As a developer, if things don’t work correctly, your natural instinct is probably to check your source code for bugs. But when you use Cocoa Touch, another dimension is added. Much of your app’s configuration may be “encoded” in the storyboard. For example, if you haven’t made the correct connections, your app won’t behave as you expect.

  • 如果点击按钮,文本没有变化,可能是你没有连接按钮动作到视图控制器,或者你没有连接视图控制器的连线到文本区或者标签。If the text doesn’t update when you click the button, it might be that you didn’t connect the button’s action to the view controller, or that you didn’t connect the view controller’s outlets to the text field or label.

  • 如果点击完成时键盘没有解除,可能是没有连接文本区代理,或者没有连接视图控制器的文本区属性连线到文本区。要连接文本区到 stroyboard:控制-点击文本区,解开半透明的连接面板。你应该使代理连线和文本区映射连线的环形图标变成实心。If the keyboard does not disappear when you click Done, you might not have connected the text field’s delegate or connected the view controller’s textField outlet to the text field. Be sure to check the text field’s connections on the storyboard: Control-click the text field to reveal the translucent connections panel. You should see filled-in circles next to the delegate outlet and the textField referencing outlet.

    如果你已经连接了代理,可能会有一个更微妙的问题(查看下一章:“代理方法名称”)。If you have connected the delegate, there might be a more subtle problem (see the next section, “Delegate Method Names”).

代理方法名字Delegate Method Names

一个常见的关于代理的错误是拼错了代理方法名。如果你已经正确设置代理对象,如果代理没有在实现该方法使用正确的名字,正确的方法是不会被调用的。最好是复制并粘贴代理方法的声明到头文件,例如从文件复制并粘贴 textFieldShouldReturn: 方法。A common mistake with delegates is to misspell the delegate method name. Even if you’ve set the delegate object correctly, if the delegate doesn’t use the right name in its method implementation, the correct method won’t be invoked. It’s usually best to copy and paste delegate method declarations, such as textFieldShouldReturn:, from the documentation.

代码清单Code Listings

这一节提供HelloWorldViewController类的接口及实现文档的清单。请注意,列表不显示注释和 Xcode 的模板所提供的其他方法实现。This section provides listings for the interface and implementation files of the HelloWorldViewController class. Note that the listings don’t show comments and other method implementations that are provided by the Xcode template.

头文件:HelloWorldViewController.hThe Interface file: HelloWorldViewController.h

#import <UIKit/UIKit.h>
 
@interface HelloWorldViewController : UIViewController <UITextFieldDelegate>
 
@property (copy, nonatomic) NSString *userName;
 
@end

实现文件:HelloWorldViewController.mThe Implementation File: HelloWorldViewController.m

#import "HelloWorldViewController.h"
 
@interface HelloWorldViewController ()
 
@property (weak, nonatomic) IBOutlet UITextField *textField;
@property (weak, nonatomic) IBOutlet UILabel *label;
 
- (IBAction)changeGreeting:(id)sender;
 
@end
 
@implementation HelloWorldViewController
 
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}
 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
 
- (IBAction)changeGreeting:(id)sender {
 
    self.userName = self.textField.text;
 
    NSString *nameString = self.userName;
    if ([nameString length] == 0) {
        nameString = @"World";
    }
    NSString *greeting = [[NSString alloc] initWithFormat:@"Hello, %@!", nameString];
    self.label.text = greeting;
}
 
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
 
    if (theTextField == self.textField) {
        [theTextField resignFirstResponder];
    }
    return YES;
}
 
@end

转载于:https://www.cnblogs.com/zyingn/articles/iOS_translation7.html

First iOS App_Troubleshooting and Reviewing the Code相关推荐

  1. iOS 的 (签名验签)Code Signing 体系

    iOS中的Code Signing体系非常复杂,对新手非常不友好,虽然目前网上已经存在大量文章对此进行比较透彻的分析,最核心的部分已经讲解得非常清楚,我阅读了这些文章后,确实从中学习到不少知识,但我始 ...

  2. iOS Provisioning Profile(配置文件)与Code Signing详解

    关于开发证书配置(Certificates & Identifiers & Provisioning Profiles),相信做iOS开发的同学没少被折腾.对于一个iOS开发小白.半吊 ...

  3. iOS Provisioning Profile(Certificate)与Code Signing详解

    引言 关于开发证书配置(Certificates & Identifiers & Provisioning Profiles),相信做 iOS 开发的同学没少被折腾.对于一个 iOS ...

  4. iOS 9 学习系列: Xcode Code Coverage

    Code coverage 是一个计算你的单元測试覆盖率的工具. 高水平的覆盖给你的单元測试带来信心.也表明你的应用被彻底的測试过了. 你可能写了几千个单元測试,但假设覆盖率不高.那么你写的这套測试可 ...

  5. iOS - 添加代码片段(Code Snippets)

    添加代码段目的是为了减少敲写重复的代码,xcode原生带有很多代码段,例如for语句.switch语句等,{}表示代码段. 代码段制作: 具体制作代码段也很简单.先选中一段代码,然后右键,选择Crea ...

  6. iOS 诡异的崩溃EXC_BREAKPOINT (code=1, subcode=0x1c5691d2c)

    系统 : iOS 13.3.1 机型: iPhone7 dispatch_async(_jsContextQueue, ^{JSContext *jscontent = [[JSContext all ...

  7. ios Flipper Thread 10: EXC_BAD_ACCESS (code=1, address=0x10001)

    每次debug都卡在这个位置(X509_NAME_add_entry_by_txt),realease模式没有问题 查看podfile use_flipper!({ 'Flipper-Folly' = ...

  8. An Overview of Cisco IOS Versions and Naming

    An Overview of Cisco IOS Versions and Naming http://www.ciscopress.com/articles/article.asp?p=210654 ...

  9. 10个优秀的Objective-C和iOS开发在线视频教程

    如果你自己开发iOS应用,你肯定会发现网上有很多资源.学习编程的一个最好的方法就是自己写代码,而开始写代码的最快的方式就是看其他人怎么写.我们从海量视频和学习网站中整理出了我 如果你自己开发iOS应用 ...

最新文章

  1. centos代码切换图形_沙迪克慢走丝代码大全,G代码、T代码、M代码(值得收藏)...
  2. 获取当天时间的开始和结束 00:00:00和23:59:59
  3. 二分类2x2对角矩阵准确率表达式
  4. silklabo哪个公众号有资源_微小说免费渣渣团资源公众号看大全集
  5. centos8安装MySQL依赖_centos8安装mysql8
  6. html5 中 video 标签,H5页面中 video 标签的坑
  7. requirejs页面刷新失效js报错问题解决方案
  8. java画布颜色切换_在本视频讲解演示中,扩展画布的目的是为了后面制作齿孔时操作起来方便,扩展部分更换了另一种颜色,是为了以示区别,能直观区分出票面部分。...
  9. Android 系统(223)---Android-打包与快速打包
  10. in use 大学英语4word_(word)大学英语考试样题四.doc
  11. day023 常用模块02
  12. 问题1、图像分割预测时原始图片大小与预测图片大小不一致
  13. python 随机颜色
  14. ORACLE rollup函数
  15. 把照片的字转换为数字版
  16. 从苏宁电器到卡巴斯基(后传)第04篇:还愿吾爱破解视频教程大赛
  17. 显示图片的html 页面,HTML基础——网站图片显示页面
  18. 德州仪器发布99%高效GaN逆变器功率级的参考设计
  19. HinM_COMPILER_cale计划和实现
  20. 详解易经64卦-傅佩荣有声系列2

热门文章

  1. mysql为datetime类型的字段设置默认值current_timestamp,引发 Invalid default value for 错误...
  2. Callable和Future、FutureTask的使用
  3. spring 的IoC的个人理解
  4. hdu 4454 Stealing a Cake(三分之二)
  5. 产品经理学PMP,有必要吗?
  6. App推广中如何寻找200个以上渠道
  7. 美团悄悄进入企业早餐,其战略目的为高频带低频?
  8. Java 11 究竟比 8 快了多少?看看这个基准测试
  9. 远程桌面连接出现身份验证错误。 要求的函数不受支持,这可能是由于 CredSSP 加密 Oracle 修正。...
  10. powerBi odbc 连接impala 实现自助分析