2

以下のコードを使用しているセルのカスタム ラジオ ボタンで問題に直面しています。テーブル ビューですべてのセルから 1 つのセルを選択し、他のすべてのセルを選択解除できるように、ラジオ ボタン送信者アクションUItableViewViewに同じアクションを設定したいと考えています。didSelectRowAtIndexPathtableView では、ユーザーが一度に 1 つずつ選択できるすべての iPod 音楽ライブラリの曲を表示したいと考えています。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier = @"Cell_Connections";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        もし (セル == ゼロ)
        {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] ;
            cell.selectionStyle = UITableViewCellSelectionStyleGray;
            cell.detailTextLabel.textColor = [UIColor darkGrayColor];
            [セル setAccessoryType:UITableViewCellAccessoryNone];
        }

cell.backgroundColor = [UIColor whiteColor]; cell.textLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:16]; cell.textLabel.textColor = [UIColor blackColor]; cell.imageView.image = [UIImage imageNamed:@"cbimg_unselected.png"]; MPMediaItem *temp1 = [self.sectionedArtistsArray objectAtIndex:indexPath.row]; cell.textLabel.text = [temp1 valueForProperty:MPMediaItemPropertyTitle]; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; CGRect frame = CGRectMake(0.0, 0.0, 44, 41); button.frame = frame; [button setImage:[UIImage imageNamed:@"cbimg_unselected.png"] forState:UIControlStateNormal]; [button setImage:[UIImage imageNamed:@"cbimg_selected.png"] forState:UIControlStateSelected]; [button addTarget:self action:@selector(checkButtonTapped:event:) forControlEvents:UIControlEventTouchUpInside]; button.backgroundColor = [UIColor clearColor]; [cell.contentView addSubview:button]; return cell; } - (void)checkButtonTapped:(id)sender event:(id)event { NSSet *touches = [event allTouches]; UITouch *touch = [touches anyObject]; CGPoint currentTouchPosition = [touch locationInView:self.tblVwMusic]; NSIndexPath *indexPath = [self.tblVwMusic indexPathForRowAtPoint: currentTouchPosition]; if (indexPath != nil) { //[self tableView: self.tblVwMusic accessoryButtonTappedForRowWithIndexPath: indexPath]; } UIButton *button = (UIButton*)sender; for (int section = 0, sectionCount = tblVwMusic.numberOfSections; section < sectionCount; ++section) { for (int row = 0, rowCount = [tblVwMusic numberOfRowsInSection:section]; row < rowCount; ++row) { UITableViewCell *cell = [tblVwMusic cellForRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:section]]; [tblVwMusic deselectRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:section] animated:YES]; NSArray *btnsArray = [cell.contentView subviews]; for (UIButton *but in btnsArray) { if ([but isKindOfClass:[UIButton class]]) { [but setSelected:NO]; } } } } if (!button.selected) { button.selected = button.selected; }else { button.selected = !button.selected; } } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { for (int section = 0, sectionCount = tableView.numberOfSections; section < sectionCount; ++section) { for (int row = 0, rowCount = [tableView numberOfRowsInSection:section]; row < rowCount; ++row) { UITableViewCell *cell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:section]]; [tableView deselectRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:section] animated:YES]; NSArray *btnsArray = [cell.contentView subviews]; for (UIButton *but in btnsArray) { if ([but isKindOfClass:[UIButton class]]) { [but setSelected:NO]; } } } } UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; NSArray *btnsArray = [cell.contentView subviews]; for (UIButton *but in btnsArray) { if ([but isKindOfClass:[UIButton class]]) { if (!but.selected) { [but setSelected:YES]; } else { [but setSelected:NO]; } } } }
4

0 に答える 0