自定义辅助视图accessoryview
2018-08-14 本文已影响15人
洲洲哥
效果图

实现代码如下
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.mydata.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"ids"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ids"];
}
cell.textLabel.text = self.mydata[indexPath.row];
UISwitch *mySwitch = [[UISwitch alloc]init];
mySwitch.on = NO;
[mySwitch addTarget:self action:@selector(switchOnOrOff:) forControlEvents:UIControlEventValueChanged];
cell.accessoryView = mySwitch;
return cell;
}
- (void)switchOnOrOff:(UISwitch *)uiswitch {
}
有些地方说的不到位,还请各位看官指正。。。
- 如有问题可添加QQ群:234812704
- 欢迎各位一块学习,提高逼格!
- 也可以添加洲洲哥的微信公众号
可以来微信公众号(洲洲哥)后台给我们留言。 快来扫码关注我们吧!
