我将 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
myButtonPressed
在DetailViewController.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/