I'm creating an ios app where I want to use a switch as the accessory for a tableview. I've found the following sample of how to use a UISwitch as the accessory: http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/TableView_iPhone/ManageSelections/ManageSelections.html (see "Responding to Selections" section).
What I'd like to do is to use a DCRoundSwitch (https://github.com/domesticcatsoftware/DCRoundSwitch) instead of a UISwitch so I can customize the text. But when I create the accessory in the way that is suggested by the sample code, I just get the round knob, I don't get the whole switch. The code I'm using to add the accessory is:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellIdentifier = @"PersonCell"; MyPerson *person = [self.dataController objectInListAtIndex:indexPath.row]; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; DCRoundSwitch *switchObj = [[DCRoundSwitch alloc] initWithFrame:CGRectMake(1.0, 1.0, 20.0, 20.0)]; switchObj.onText = @"in"; switchObj.offText = @"out"; [switchObj addTarget:self action:@selector(personIn:) forControlEvents:(UIControlEventValueChanged | UIControlEventTouchDragInside)]; cell.accessoryView = switchObj; [[cell textLabel] setText:person.name]; [[cell detailTextLabel] setText:person.label]; return cell; }
What can I do to make the DCRoundSwitch work as a TableView accessory?
Thanks!
cell.accessoryView = switchObj;
– charleyh