English 中文(简体)
Not calling the function when I click on UIButton?
原标题:

I have an imageView and after i add it to the screen I release it. Before that I adds a button onto it with this code.

            button = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
            button.frame = CGRectMake(128.00, 128.00, 23.00, 40.00);
            [button setBackgroundImage:[UIImage imageNamed:@"move.png"] forState:UIControlStateNormal];
            [button addTarget:self action:@selector(showAddress:) forControlEvents:UIControlEventTouchUpInside];
            [imageView addSubview:button];

            - (void) showAddress:(id)sender
            {
                NSLog(@"Working");
            }

The button appears but nothing happens when I click on it to call a function. Not even the pressing-unpressing. Is this because I am releasing the imageView?

最佳回答

Edited:Check if userInteractionEnabled property of your UIImageView is set to YES - it is set to NO by default and that s why UIImageView (and its subviews) does not respond to touch events. I ve just set it to YES in my code and it works fine.

One more note - when you add your button to another view it takes the ownership of the button and as you retained it in your code you should also release it. (Or just not retain in this case)

问题回答

暂无回答




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签