ios - UIButton 不会隐藏/取消隐藏

标签 ios iphone objective-c uibutton

我将 UIButton myButton 设置为在 viewDidLoad 上隐藏

splitviewcontroller 中,当我点击 tablecell 时,某些项目会取消隐藏,这对我的 textviews 非常有用,但我的按钮给了我这个:

ERROR: member reference base type void is not a structure or union

这里是一些代码片段:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    if (indexPath.row == 0) {



        detailViewController.myButton.hidden= NO;
        detailViewController.textView1.hidden= NO;
        detailViewController.textView2.hidden= NO;

    }

.h文件中有

@property (strong, nonatomic) DetailViewController *detailViewController;

DetailViewController 中,按钮和 textviews 被声明为

@interface DetailViewController : UIViewController <UISplitViewControllerDelegate>{

    IBOutlet UIButton *myButton;
    IBOutlet UITextView *textView1;
    IBOutlet UITextView *textView2;
}


@property (strong, nonatomic) IBOutlet UITextView *textView1;
@property (strong, nonatomic) IBOutlet UITextView *textView2;
@property (strong, nonatomic) UIButton *myButton;


-(IBAction)myButtonPressed; 
@end

IBAction myButtonPressedDetailViewController.m

-(IBAction)myButtonPressed{

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    RootViewController *RVC = [storyboard instantiateViewControllerWithIdentifier:@"Root"];
    [UIApplication sharedApplication].delegate.window.RootViewController = RVC;


}

有人想知道为什么按钮的行为与其他两个不同吗?是不是因为我给了它一个IBAction??

最佳答案

你忘了把 IBOutlet 放在创建按钮的第一个位置,它应该是

@property (strong, nonatomic) IBOutlet UIButton *myButton; OR
@property (nonatomic, weak) IBOutlet UIButton *myButton;

并为文件的所有者提供正确的连接。

关于ios - UIButton 不会隐藏/取消隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21449554/

相关文章:

ios - 对于仅适用于 iPhone 的 iOS 7+ 应用程序,我们可以仅包含 @3x 图像吗?

ios - 在场景工具包 ios swift 中创建一个二维图像作为 SCNNode

ios - 带有导航 Controller 方向的标签栏 Controller ios 6

iPhone核心数据与Ruby on Rails同步

ios - 如何修改我的应用程序概念以通过包含原生 iOS 特性和功能来提供更强大的用户体验?

objective-c - 从drawAtPoint绘制的屏幕中删除字符串

ios - UICollectionViewCell 中的 subview Controller

iphone - 点击/单击查看操作 Xcode

ios - 水平滚动时 ScrollView 的默认方法是什么?

iphone - 将 UIWebView 标题发送到 UINavigationBar