【问题标题】:DCRoundSwitch as AccessoryDCRoundSwitch 作为附件
【发布时间】: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


【解决方案1】:

我认为您的宽度只是为了缩小宽度——尝试将宽度设置为 60 或 70(故事板中 UISwitch 的默认宽度为 79)。

【讨论】:

  • 嗯。这会使圆圈变大,但不会使滑块的其余部分出现。我想知道它是否与将其用作附件有关-普通附件(复选标记,>等)非常窄-想知道如果允许滑块部分,我是否可以强制附件变宽出现。
  • @nojo,我不知道你为什么会看到这个结果——我把它用作附件视图,使用与你所拥有的几乎相同的代码,它运行良好(使用大小为 65,22)。
猜你喜欢
  • 1970-01-01
  • 2012-09-17
  • 2015-10-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-10
  • 1970-01-01
  • 2013-01-03
相关资源
最近更新 更多