我正在创建一个 ios 应用程序,我想在其中使用开关作为 tableview 的附件。我找到了如何使用 UISwitch 作为附件的以下示例:http: //developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/TableView_iPhone/ManageSelections/ManageSelections.html(请参阅“响应选择”部分)。
我想做的是使用 DCRoundSwitch ( https://github.com/domesticcatsoftware/DCRoundSwitch ) 而不是 UISwitch ,这样我就可以自定义文本。但是当我按照示例代码建议的方式创建附件时,我只得到了圆形旋钮,我没有得到整个开关。我用来添加附件的代码是:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
静态 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;
[[单元格文本标签] setText:person.name];
[[cell detailTextLabel] setText:person.label];
返回单元格;
}
我该怎么做才能使 DCRoundSwitch 作为 TableView 附件工作?
谢谢!