我有一个简单的问题,我似乎无法找到答案.
我有几个UIButtons存储在一个NSArray,有一个for循环设置button.selected = YES时,他们被轻拍.我需要在点击时取消选择相同的按钮,但我似乎无法在网上找到任何帮助.这是我的代码:
- (IBAction)buttonPressed:(UIButton *)sender {
NSArray *buttons = [NSArray arrayWithObjects:_asbBtn, _vwfBtn, _bpBtn, _rtaBtn, _mslmBtn, _pbaBtn, _rcfBtn, _mspBtn, _wpBtn, _aawBtn, _ppiBtn, _convBtn, nil];
// Select buttons
for (UIButton *button in buttons) {
if (button == sender) {
button.selected = YES;
}
}
}
Run Code Online (Sandbox Code Playgroud)
也许这不是最好的方法,对不起,如果我错过了一些简单的事情.我尝试过添加,else { button.selected = NO;但这只允许选择一个按钮并取消选择所有其他按钮.有人可以指导我正确的方向,在点击时取消选择当前选定的按钮.
我有一个NSArray包含NSDictionary客户数据.我使用的NSPredicate过滤array,并使之通过ViewControllers用segues.我正处于一个阶段,我想改变存储在其中的键的一些值dictionary.这怎么可以实现?
我的prepareForSegue方法
if ([[segue identifier] isEqualToString:@"showClients"]) {
// Detect selected row
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
// Extract value from the Clinic_Location attribute
NSString *cString = [[_clinicList valueForKey:@"Clinic_Location"] objectAtIndex:indexPath.row];
NSLog(@"Row pressed: %@", cString);
// Set predicate where Clinic_Location equals the clinic string extracted from the selected row
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"Clinic_Location == %@", cString];
// Filter the client array using this predicate
filteredClientArray …Run Code Online (Sandbox Code Playgroud) objective-c ×2
ios ×1
nsarray ×1
nsdictionary ×1
nspredicate ×1
segue ×1
uibutton ×1
xcode5 ×1