日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

First iOS App_Troubleshooting and Reviewing the Code

發布時間:2025/3/20 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 First iOS App_Troubleshooting and Reviewing the Code 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

錯誤檢查和代碼重查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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。