所以在我的VC1.h
我得到:
@property (weak, nonatomic) IBOutlet UIButton *monthly;
这与连接到VC1
类的视图上的按钮相连。如何.enabled
在不同的类中访问此按钮的属性?
编辑:
我有一个连接到 tableview 的类。在表格视图中选择特定行时,我想禁用主类中的按钮。我只需要知道如何获取按钮的当前状态并在另一个类中禁用它。
来自按钮的 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;
}
}
表视图.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];
}
以上是可能对这个问题很重要的代码部分。