【发布时间】:2013-05-21 20:13:33
【问题描述】:
我正在创建一个 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 附件工作?
谢谢!
【问题讨论】:
-
实际将开关分配给附件视图的代码在哪里?如
cell.accessoryView = switchObj; -
确认,复制/粘贴错误。更新了代码以包含它。希望它是一致的 - 我一直在玩代码。
标签: ios objective-c uitableview