ios UISwitch in a UITableView cell
2012-05-16 14:15
357 查看
文章来源:http://stackoverflow.com/questions/3770019/uiswitch-in-a-uitableview-cell
Setting it as the accessoryView is usually the way to go. You can set it up in
may want to use target/action to so something when the switch is flipped. Like so:
Setting it as the accessoryView is usually the way to go. You can set it up in
tableView:cellForRowAtIndexPath:You
may want to use target/action to so something when the switch is flipped. Like so:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { switch( [indexPath row] ) { case MY_SWITCH_CELL: { UITableViewCell* aCell = [tableView dequeueReusableCellWithIdentifier:@"SwitchCell"]; if( aCell == nil ) { aCell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"SwitchCell"] autorelease]; aCell.textLabel.text = @"I Have A Switch"; aCell.selectionStyle = UITableViewCellSelectionStyleNone; UISwitch *switchView = [[UISwitch alloc] initWithFrame:CGRectZero]; aCell.accessoryView = switchView; [switchView setOn:NO animated:NO]; [switchView addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged]; [switchView release]; } return aCell; } break; } return nil; } - (void) switchChanged:(id)sender { UISwitch* switchControl = sender; NSLog( @"The switch is %@", switchControl.on ? @"ON" : @"OFF" ); }
相关文章推荐
- How to stop UITableView from clipping UITableViewCell contents in iOS 7
- iOS 坑点 Assertion failure in - UITableView dequeueReusableCellWithIdentifier:forIndexPath:
- iOS 运行出现:Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /Sourc
- iOS Assertion failure in -[UITableView _classicHeightForRowAtIndexPath:]
- iOS中对UITableView中的cell设置自动适应行高
- ios uitableview 刷新某一个cell 或 section
- IOS学习之UITableView中Cell的操作
- IOS--常用控件--UITableView--xib自定义cell
- IOS开发(28)UITableView之移动Section和Cell
- iOS 在一个UITableview中添加多个UIViewCell
- [IOS]UITableView实现Cell的滑动删除
- iOS开发:UITableView的优化技巧-异步绘制Cell
- 墨珞随笔 - IOS - 自定义UITableView的cell - 李江辉
- iOS开发之高级视图—— UITableView(四)自定义Cell
- ios UITableview 刷新某一个cell 或 section
- ios UITableview 刷新某一个cell 或 section
- iOS UITableView表视图(3)自定义cell
- iOS代码自定义UITableView Cell(每个Cell的高度不一样)
- ios tableView那些事 (十六) UITableView中Cell重用机制导致内容重复解决方法
- iOS UITableView cell accessoryType single checkmark