简体   繁体   English

iOS SDK 5.0 iPhone应用程序故障

[英]iOS SDK 5.0 iPhone Application Trouble

I'm working on my first iPhone application and have stumbled upon an unknown bug in my code. 我正在开发我的第一个iPhone应用程序,却偶然发现了我代码中的一个未知错误。 The code works perfectly fine, but the problem lies when I tap a custom UIButton I've made and when it loads the next view. 该代码可以正常工作,但是问题出在我点击自己创建的自定义UIButton以及加载下一个视图时。 I have a desired buttonPressed IBAction that is called to handle what information loads on the next view controller, but the order of the function calls is wrong. 我有一个期望的buttonPressed IBAction,它被调用来处理在下一个视图控制器上加载的信息,但是函数调用的顺序是错误的。 I have 5 different buttonPressed functions and 3 out of the 5 are working correctly. 我有5种不同的buttonPressed功能,其中5种功能正常。 Note I implemented them the same exact way through Storyboard and even tried re-making the non-working ones. 请注意,我通过Storyboard以完全相同的方式实现了它们,甚至尝试重新制作了无效的东西。 I'd post code but the code is basic if/else statements. 我会发布代码,但是代码是基本的if / else语句。 I'm just not sure why 3 out of the 5 ways would work and the other 2 wouldn't. 我只是不确定为什么5种方法中的3种会起作用,而其他2种却不起作用。 Any help would be GREATLY appreciated. 任何帮助将不胜感激。

**This is the desired order for the working 3: **这是工作3的理想顺序:

viewDidLoad -> Loads main screen (initial view controller AKA ROOT, On main screen, you have 5 UIButtons to choose a category, tap a button to load to a new view controller) viewDidLoad->加载主屏幕(初始视图控制器又名ROOT,在主屏幕上,您有5个UIButton来选择类别,点击一个按钮以加载到新的视图控制器)

categoryButtonPressed -> Sets counter (seques to new view controller) categoryButtonPressed->设置计数器(相当于新的视图控制器)

viewDidLoad -> Loads Screen to narrow down search viewDidLoad->加载屏幕以缩小搜索范围

(Now you have 10+ Custom Buttons to Tap on, each will be handled through a buttonPressed IBAction function, and once button is tapped and function is called, a new view is loaded) (现在您有10个以上的自定义按钮可以点击,每个按钮都将通过buttonPressed IBAction函数进行处理,一旦点击按钮并调用该函数,就会加载一个新视图)

buttonPressed -> Sets counter (seques to new view controller) buttonPressed->设置计数器(相当于新的视图控制器)

viewDidLoad -> Loads correct information viewDidLoad->加载正确的信息

This is the order for the non-working 2: 这是不工作2的顺序:

viewDidLoad -> Loads main screen (initial view controller AKA ROOT) (On main screen, you have 5 UIButtons to choose a category, tap a button to load to a new view controller) viewDidLoad->加载主屏幕(初始视图控制器又名ROOT)(在主屏幕上,您有5个UIButton来选择类别,点击一个按钮以加载到新的视图控制器)

categoryButtonPressed -> Sets counter (seques to new view controller) categoryButtonPressed->设置计数器(相当于新的视图控制器)

viewDidLoad -> Loads Screen to narrow down search (Now you have 10+ Custom Buttons to Tap on, each will be handled through a buttonPressed IBAction function, and once button is tapped and function is called, a new view is loaded) viewDidLoad->加载屏幕以缩小搜索范围(现在有10个以上的自定义按钮可供点击,每个按钮都将通过buttonPressed IBAction函数进行处理,一旦点击并调用该函数,就会加载一个新视图)

viewDidLoad -> Loads blank information (blank screen) viewDidLoad->加载空白信息(黑屏)

buttonPressed -> Sets counter but is to late as the view already was loaded blank buttonPressed->设置计数器,但由于视图已被加载为空白而延迟

Thoughts?** 有想法吗?**

Here is an example of the categoryButtonPressed: 这是categoryButtonPressed的示例:

-(IBAction)categoryButtonPressed:(id)sender -(IBAction)categoryButtonPressed:(id)发送者

{ {

if([sender tag] == 1)

    counter = 1;

else if([sender tag] == 2)

    counter = 2;

.

.

.

} }

NOTE: I have each custom button tagged for a specific item to be loaded. 注意:我有每个自定义按钮标记为要加载的特定项目。 This function is just to set a counter so another function can load a specific file. 此功能仅用于设置计数器,以便另一个功能可以加载特定文件。

Use segues. 使用segues。

On your main view controller set up the segues by loading the desired information on the view controller when a specific segue is pressed. 在主视图控制器上,通过按特定的按钮将所需信息加载到视图控制器上来设置按钮。

You can follow this guide which is the way you should do it if you are using story boards 如果您使用故事板,则可以按照本指南进行操作。

http://www.scott-sherwood.com/?p=219 http://www.scott-sherwood.com/?p=219

Look for the "prepareForSegue" methods, when using storyboards, modally presented views should be pre configured this way. 在使用情节提要时,请寻找“ prepareForSegue”方法,以这种方式预先配置模态呈现的视图。

On a side note, the "viewDidLoad" is usually not used to load another view, it should be used to configure that view after it has been loaded. 附带说明一下,“ viewDidLoad”通常不用于加载另一个视图,应在加载该视图后用于配置该视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM