标签: ibaction

多个UIAlertView; 每个都有自己的按钮和动作

我在Xcode 4.3中创建一个视图,我不确定如何指定多个UIAlertView,它们有自己的按钮和单独的动作.目前,我的警报有自己的按钮,但操作相同.以下是我的代码.

-(IBAction)altdev {
    UIAlertView *alert = [[UIAlertView alloc] 

                          initWithTitle:@"titleGoesHere"
                          message:@"messageGoesHere"
                          delegate:self
                          cancelButtonTitle:@"Cancel"
                          otherButtonTitles:@"Continue", nil];
[alert show];
}

-(IBAction)donate {
    UIAlertView *alert = [[UIAlertView alloc] 

                          initWithTitle:@"titleGoesHere"
                          message:@"messageGoesHere"
                          delegate:self
                          cancelButtonTitle:@"Cancel"
                          otherButtonTitles:@"Continue", nil];
    [alert show];
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 1) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.examplesite1.com"]];
         }
}


-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 1) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"examplesite2.com"]];
    }
}  
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助!

xcode button uialertview ibaction

16
推荐指数
2
解决办法
2万
查看次数

如何访问超类中声明的IBOutlet?

我目前正在重构一些共享一些IBOutlets和IBAction方法的视图控制器.我将插座声明和IBAction方法移动到一个超类中,从子类中删除它们.

现在,当我打开Interface Builder时,我发现我无法看到超类中声明的出口或动作.这些连接仍然存在,因为我在重构之前将它们连接起来,但是它们已经变灰了.(重要的是要注意连接也是工作,因为我的操作在按下按钮时触发,我的插座被正确修改.)

问题是,如何让界面构建器识别来自超类的出口?这是可能的,如果没有,你们都推荐什么?

(只是为了好玩,这是我的超类头文件:)

@interface TFMainViewController : UIViewController {
    UIImageView *logoImage, *thinkfunImage;
    UIButton *buyFullButton;        
}

@property (nonatomic, retain) IBOutlet UIImageView *logoImage, *thinkfunImage;
@property (nonatomic, retain) IBOutlet UIButton *buyFullButton;

-(IBAction) buyFullVersion;

@end
Run Code Online (Sandbox Code Playgroud)

编辑:如果有人想知道,我正在使用Xcode和IB 3.2.5,iOS 4.2 SDK.

xcode interface-builder iboutlet ibaction ios

15
推荐指数
2
解决办法
1万
查看次数

Xcode 8拖动并连接@IBAction错误地在连接检查器IB上添加"WithSender"

Xcode 8拖动并连接@IBAction错误地在连接检查器IB上添加"WithSender"

因此,我必须将方法重命名为类似的方法

@IBAction func tappedConfirmButtonWithSender(sender:AnyObject){}

不应该吗?:

@IBAction func tappedConfirmButton(sender:AnyObject){}

这是我的错还是这个错误?

ibaction xcode8

15
推荐指数
1
解决办法
4726
查看次数

Swift - 在没有参数的viewDidLoad中调用@IBAction方法

@IBAction func getNewPhotoAction(sender: AnyObject) {
    println("getNewPhotoAction")
}

override func viewDidLoad() {
    super.viewDidLoad()
    self.getNewPhotoAction(sender: AnyObject) // Error
}
Run Code Online (Sandbox Code Playgroud)

我只是想调用getNewPhotoActionIBAction方法viewDidLoad.

在这一行输入哪个参数 - > self.getNewPhotoAction(?????)

我没有任何参数.我只需要打电话.

我用Objective-C风格:

[self getNewPhotoAction:nil]
Run Code Online (Sandbox Code Playgroud)

但我不知道斯威夫特的风格.

parameters ibaction swift

14
推荐指数
3
解决办法
2万
查看次数

将不同的参数传递给IBAction

我的iPhone应用程序有很多按钮,我希望所有按钮调用相同的方法,但具有不同的参数.

例如,我想点击一个按钮来myMethod:使用参数调用方法,@"foo"第二个按钮应该使用参数调用相同的方法@"bar".

cocoa-touch objective-c ibaction ios

13
推荐指数
1
解决办法
2万
查看次数

如何在IB(iPhone/iPad)中使用手势识别器?

我刚刚在IB中发现了手势识别器,我想利用它们.我已经尝试过Tap Gesture Recognizer但它似乎不起作用.这就是我所做的......

  1. 将"Tap Gesture Recognizer"拖放到IB中的视图控制器中.

  2. 在.m文件中添加了以下方法...

    - (IBAction)viewTapped:(UIGestureRecognizer *)sender
    {
        // Do some stuff
    }
    
    Run Code Online (Sandbox Code Playgroud)
  3. 声明.h文件中的方法...

    - (IBAction)viewTapped:(UIGestureRecognizer *)sender;
    
    Run Code Online (Sandbox Code Playgroud)
  4. 最后,我将IBAction与IB中的"Tap Gesture Recognizer"联系起来.

当我尝试运行时,我没有成功 - 我错过了什么吗?

iphone interface-builder ibaction uigesturerecognizer uitapgesturerecognizer

13
推荐指数
2
解决办法
1万
查看次数

按下键盘上的返回键时的操作(iOS)

- (BOOL)textFieldShouldReturn:(UITextField *)textField 
{
    [self checkRun:nil];
    return YES;
}
Run Code Online (Sandbox Code Playgroud)

我试图IBAction checkRun通过使用上面的代码完成按下返回键的时间,但它似乎没有工作.我哪里错了?我想也许是因为我没有直接引用我正在输入的文本字段,但我无法确定我需要将该文本字段的名称放在哪里.

提前致谢.

objective-c uitextfield ibaction ios

13
推荐指数
1
解决办法
2万
查看次数

UITableViewCell中的IBAction未在iOS 9中调用

我有一个自定义UITableViewCell子类,其中包含IBAction从nib连接的一些方法.

在iOS 8下,一切都按预期工作.如果用户点击其中一个按钮,IBAction则调用相应的按钮.如果用户点击单元格上的任何其他位置,UITableView didSelectRowAtIndexPath则会调用该单元格.

在iOS 9下,我的IBAction方法永远不会被调用.UITableView didSelectRowAtIndexPath无论用户在单元格中的哪个位置(按钮与否),都会始终触发.

该项目是在Xcode 6/Swift 1.2下编译的.

我在Apple论坛上发现这篇文章没有解决方案.他们似乎有同样的问题.

https://forums.developer.apple.com/thread/16179

uitableview ibaction ios swift

12
推荐指数
2
解决办法
5885
查看次数

UIButton事件'Touch Up Inside'无效.'Touch Down'工作得很好

我在UIView中有一个UIButton,它位于UIViewController中,我已经从.xib文件中分配和输入.

当将IBAction挂钩到UIButton的"Touch Down"事件时,它会正确触发.但如果我把它连接到'Touch Up Inside'事件,它就不会响应.

其他事件也不起作用.'触摸拖动输入','触摸拖动退出','触摸外部'等.仅触摸向下.

有谁知道为什么会这样?


该按钮是视图控制器中的简单圆角矩形按钮.我已经加载了视图控制器:

-(void) pushNewViewController
{
    MyViewController* newViewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
    [self.view addSubview:newViewController.view];
    [newViewController release];
}
Run Code Online (Sandbox Code Playgroud)

我在IB中将此按钮添加到圆形rect按钮到MyViewController.我创建了以下IBActions:

-(IBAction) buttonTouchDown:(id)sender
{
    NSLog(@"Button Touch Down Event Fired.");
}

-(IBAction) buttonTouchUpInside:(id)sender
{
    NSLog(@"Button Touch Up Inside Event Fired.");
}
Run Code Online (Sandbox Code Playgroud)

在IB I菜单中单击按钮并将Touch Down插座拖动到MyViewController并选择buttonTouchDown:.保存了IB xib.

当我运行并测试按钮并获得"Button Touch Down Event Fired"日志消息时.

但是当我回到IB并将Action更改为Touch Up Inside并将其连接到buttonTouchUpInside:IBAction并保存.我再次测试,没有得到回应.

此致,Rich

iphone touch uibutton uikit ibaction

11
推荐指数
3
解决办法
2万
查看次数

如果它们都具有相同的IBAction,如何定义按下哪个按钮?

我有两个UIButtons(我使用IB创建它们),它使用相同的IBAction连接到File的所有者,我如何定义哪些被按下?

objective-c uibutton ibaction ios

11
推荐指数
2
解决办法
2万
查看次数