2013-12-17 16 views
0

我有一个UIButton,它有多种方法。正如你将在我的代码中看到的那样,每当你按下UIButton时,它就会改变它的标签,从而让我每次都做一件不同的事情(所以第一次做事A,第二次做事B等)。我发现由于某种原因,iPhone每次都会执行两种这样的方法,所以我在每个真正的方法之间添加了一种无用的方法。这是完美的工作,但由于某种原因,它只是停止工作,我不知道为什么。现在它在第一个UIButton印刷机上得到一个断线。任何帮助表示赞赏。基于标签的多功能UIButton线程中断UILabel

ViewController.h:

#import <UIKit/UIKit.h> 

@interface ViewController : UIViewController <UITextViewDelegate> { 
    IBOutlet UITextView *textEnterView; 
    IBOutlet UILabel *promptLabel; 
    IBOutlet UIButton *nextButton; 

    NSString *topicString; 
    NSString *firstString; 
    NSString *firstSubString; 
    NSString *secondString; 
    NSString *secondSubString; 
    NSString *thirdString; 
    NSString *thirdSubString; 
    NSString *conclusionString; 
} 
@property (nonatomic, retain) UITextView *textEnterView; 
@property (nonatomic, retain) UILabel *promptLabel; 
@property (nonatomic, retain) UIButton *nextButton; 

@property (nonatomic, retain) NSString *topicString; 
@property (nonatomic, retain) NSString *firstString; 
@property (nonatomic, retain) NSString *firstSubString; 
@property (nonatomic, retain) NSString *secondString; 
@property (nonatomic, retain) NSString *secondSubString; 
@property (nonatomic, retain) NSString *thirdString; 
@property (nonatomic, retain) NSString *thirdSubString; 
@property (nonatomic, retain) NSString *conclusionString; 


- (IBAction) next:(id)sender; 
@end 

ViewController.m:

#import "ViewController.h" 

@interface ViewController() 

@end 

@implementation ViewController 
@synthesize textEnterView, promptLabel, nextButton, firstSubString, firstString, secondSubString, secondString, thirdSubString, thirdString, conclusionString, topicString; 

- (void)viewDidLoad 
{ 
    UIButton *button = nextButton; 
    [button setTag:1234]; 
    [button addTarget:self action:@selector(next:) forControlEvents:UIControlEventTouchUpInside]; 
    textEnterView.delegate = self; 
    promptLabel.text = @"First Label"; 
    textEnterView.text = @" "; 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 

} 
- (IBAction) next:(UIButton *)sender { 
    if(nextButton.tag==1234) { 
    promptLabel.text = @"Second Label"; 
     [nextButton setTag:2]; 
     topicString = textEnterView.text; 
     //FAKE METHOD 
    } 
    else if (nextButton.tag==2) { 
     promptLabel.text = @"Third Label"; 
     textEnterView.text = @" "; 
     [nextButton setTag:3]; 
     //REAL METHOD 
    } 
    else if (nextButton.tag==3) { 
     promptLabel.text = @"Fourth Label"; 
     firstString = textEnterView.text; 
     [nextButton setTag:4]; 
     //FAKE METHOD 
    } 
    else if (nextButton.tag==4) { 
     promptLabel.text = @"Fifth Label"; 
     textEnterView.text = @" "; 
     [nextButton setTag:5]; 
     //REAL METHOD 
    } 

    else if (nextButton.tag==5) { 
     promptLabel.text = @"Sixth Label"; 
     firstSubString = textEnterView.text; 
     [nextButton setTag:6]; 
     //FAKE METHOD 
    } 
    else if (nextButton.tag==6) { 
     promptLabel.text = @"Seventh Label"; 
     textEnterView.text = @" "; 
     [nextButton setTag:7]; 
     //REAL METHOD 
    } 
    else if (nextButton.tag==7) { 
     promptLabel.text = @"Eighth Label"; 
     secondString = textEnterView.text; 
     [nextButton setTag:8]; 
     //FAKE METHOD 
    } 
    else if (nextButton.tag==8) { 
     promptLabel.text = @"Ninth Label"; 
     textEnterView.text = @" "; 
     [nextButton setTag:9]; 
    //REAL METHOD 
    } 
    else if (nextButton.tag==9) { 
     promptLabel.text = @"Tenth Label"; 
     secondSubString = textEnterView.text; 
     [nextButton setTag:10]; 
    //FAKE METHOD 
    } 
    else if (nextButton.tag==10) { 
     promptLabel.text = @"Eleventh Label"; 
     textEnterView.text = @" "; 
     [nextButton setTag:11]; 
    //REAL METHOD 
    } 
    else if (nextButton.tag==11) { 
     promptLabel.text = @"Twelfth Label"; 
     thirdString = textEnterView.text; 
     [nextButton setTag:12]; 
    //FAKE METHOD 
    } 
    else if (nextButton.tag==12) { 
     promptLabel.text = @"Thirteenth Label"; 
     textEnterView.text = @" "; 
     [nextButton setTag:13]; 
    //REAL METHOD 
    } 
    else if (nextButton.tag==13) { 
     promptLabel.text = @"Fourteenth Label"; 
     thirdSubString = textEnterView.text; 
     [nextButton setTag:14]; 
    //FAKE METHOD 
    } 
    else if (nextButton.tag==14) { 
     promptLabel.text = @"Fifteenth Label"; 
     textEnterView.text = @" "; 
     [nextButton setTag:15]; 
    //REAL METHOD 
    } 
    else if (nextButton.tag==15) { 
     promptLabel.text = @"Sixteenth Label"; 
     conclusionString = textEnterView.text; 
     [nextButton setTag:16]; 
    } 
    else if (nextButton.tag==16) { 
     promptLabel.text = @"Seventeenth Label"; 
     textEnterView.text = @" "; 
     [nextButton setTag:17]; 
    } 
    else if (nextButton.tag==17) { 
     [nextButton setTag:18]; 
    } 
    else { 
     promptLabel.text = @"Eighteenth Label"; 
     [nextButton setTag:1234]; 
    } 

} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

@end 

显然,唱片公司说,除了只是一些 “第十八标签,” 但如果我发现了什么,为什么说我会一直远离应用程序的想法。但是,所有其他代码与应用程序中的完全相同。感谢您的任何帮助!

+0

我会从剥离假货开始。您只需更改触摸事件中的标签即可。 – nhgrif

+0

我觉得我确实改变了触摸事件中的标签......我不明白为什么它每次都会使用两种方法,但如果能详细说明您的意思,可以高兴地删除假货。我应该在哪里设置标签?你的意思是我的标记设置为1234最初应该发生在方法中,但在子方法之外(或者你想要调用它们的任何东西)而不是在viewDidLoad中?如果是这样,为什么这会使iPhone/iPod一次开始执行一个子方法而不是两个?谢谢! –

+0

因为您正在调用标签'1234'或任何标签的方法,并且您在更改标签的同时按钮仍然按下,所以下一个方法会触发。我想如果你真的把按钮按下了足够长的时间,许多方法都会触发。如果在释放按钮时将标签更改为动作触发,则不应该获得双方法调用。充满假方法调用的堆是sl ... ... – nhgrif

回答

0

我在iPod Touch上运行了它,它非常有效 - 但只有在未插入计算机时才有效。我认为Xcode会以某种方式搞砸它,因为该应用程序在iPod未连接时运行,但在连接并且计算机正在记录结果时不起作用。然而,重要的是它的工作是独立的,所以虽然错误的原因仍然是未知的,但它被解决,因此并不重要。但是,如果有人提出解决方案来解释这个问题,我当然会将其作为问题的官方“答案”。可能的问题是,它正在构建错误的构建设置,如Arm__(在__中是错误的字母 - 不确定哪些是正确的,哪些不是)。无论如何,这个问题似乎被奇怪地解决了。