所以在VC1.h
我得到了:
@property (weak, nonatomic) IBOutlet UIButton *monthly;
这是连接到视图上的按钮,该按钮连接到VC1
类。
如何在其他类中访问此按钮的.enabled
属性?
编辑:
我有一个连接到tableview的类。在tableview中选择特定行时,我想在我的mainclass中禁用一个按钮。我需要知道的是如何获取按钮的当前状态并在另一个类中禁用它。
来自按钮的IBaction:
- (IBAction)monthly:(id)sender {
[monthly setSelected:YES];
yearly.enabled = YES;
if([monthly isSelected])
{
NSLog(@"monthly ON");
[yearly setSelected:NO];
monthly.enabled = NO;
_dateSpecifiedYearButton.hidden = TRUE;
_dateSpecifiedYearButton.enabled = NO;
_dateSpecifiedButton.hidden = FALSE;
_dateSpecifiedButton.enabled = YES;
}
}
Tableview.m:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[popoverSpending dismissPopoverAnimated:YES];
UITableViewCell *cell = (UITableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
if([self.delegate respondsToSelector:@selector(spendingButtonText:)]) {
[self.delegate spendingButtonText:cell.textLabel.text];
}
if (indexPath.row == 2) {
NSLog(@"2");
ViewController *vc = [[ViewController alloc] init];
if (vc.monthly.enabled)
{
vc.monthly.enabled = NO;
vc.yearly.enabled = NO;
}
}
[self dismissViewControllerAnimated:YES completion:nil];
}
以上是代码中可能对此问题很重要的部分。
答案 0 :(得分:0)
VC1 *vc = [[VC1 alloc] init];//Allocate VC1 in appDelegate, if you allocate VC1 in VC2, then it allocates new instance.
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if (app.vc.monthly.enabled)//chk button state
{
}