【问题标题】:Can't seem to get my UIButton to hide or change coordinates似乎无法让我的 UIButton 隐藏或更改坐标
【发布时间】:2011-03-24 21:44:17
【问题描述】:

我的应用程序的基本前提是当它加载时,它隐藏按钮“findme”,然后选择按钮“go”时,它显示按钮并将其设置为特定的坐标(一旦我修复此问题,我将实现随机坐标)。问题是当应用程序加载时我的按钮没有隐藏,并且“开始”按钮没有改变坐标。我在界面生成器中创建了按钮。我不确定为什么这不起作用,因为这似乎是一项简单的任务。非常感谢我出错的任何帮助。谢谢。

.h 文件

#import <UIKit/UIKit.h>

@interface Senior_DesignViewController : UIViewController 
<UIAlertViewDelegate> {
    IBOutlet UIButton *findMe;
    IBOutlet UIButton *go;
    IBOutlet UILabel *success;
}

@property (retain, nonatomic) UIButton *findMe;
@property (retain, nonatomic) UILabel *success;
@property (retain, nonatomic) UIButton *go;

-(IBAction)foundMe:(id)sender;
-(IBAction)go:(id)sender;

@end

.m 文件

#import "Senior_DesignViewController.h"

@implementation Senior_DesignViewController

@synthesize findMe;
@synthesize success;
@synthesize go;

-(IBAction)foundMe:(id)sender {
    UIAlertView *alertDialog;
    alertDialog = [[UIAlertView alloc]
                   initWithTitle:@"Congratulations" 
                   message:@"You have found the box" 
                   delegate:nil 
                   cancelButtonTitle:@"Ok" 
                   otherButtonTitles:nil];
    [alertDialog show];
    [alertDialog release];
}

-(IBAction)go:(id)sender {

    findMe.frame = CGRectMake(100, 100, 50, 50);
    findMe.hidden = NO; 
}

- (void)viewDidLoad {

    findMe.hidden = YES;

    UIAlertView *alertDialog;
    alertDialog = [[UIAlertView alloc]
                    initWithTitle:@"Welcome to our SNR DSN App" 
                    message:@"Please Calibrate NOW!" 
                    delegate:nil 
                    cancelButtonTitle:@"Ok" 
                    otherButtonTitles:nil];
    [alertDialog show];
    [alertDialog release];

    [super viewDidLoad];
}

【问题讨论】:

  • 您是否已将 IBOutlet 成员附加到 IB 中的按钮?
  • 该死的。这太简单了,我觉得很愚蠢。应该仔细检查那个错误。是否已处理 IBActions。非常感谢。
  • 在它发生 次之前不要感到愚蠢 :)
  • 哈哈,我不想这样。我的高级项目是为 FDA 创建一个 iPhone 应用程序,我正在从头开始学习 Obj-C 编码,所以我认为在此过程中会遇到这样愚蠢的道路颠簸。再次感谢大家。
  • 别难为情,我有时还是忘记勾搭他们。 ;)

标签: iphone xcode button


【解决方案1】:

确保在 Interface Builder 中连接了出口和操作。按钮应作为引用插座附加到文件所有者,并且操作应连接到 Touch Up Inside 事件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-19
    • 2021-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-26
    • 1970-01-01
    相关资源
    最近更新 更多