以编程方式在单元格内添加UiStepper [英] Add UiStepper programmatically inside cells

查看:43
本文介绍了以编程方式在单元格内添加UiStepper的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以编程方式将UIStepper添加到UITableView的每个单元格中?

how do I add a UIStepper to every cell of my UITableView programmatically?

谢谢

路卡

推荐答案

一种实现方法是将UIStepper作为子视图添加到每个单元格,作为TableViewController中tableView:cellForRowIndexAtPath的子视图.例如:

One way to do it is to add the UIStepper to each cell as a subview in tableView:cellForRowIndexAtPath in your TableViewController. For example:

- (UITableViewCell*) tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   static NSString* CellIdentifier = @"Cell";

   UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
   if (cell == nil)
   {
       cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];

       UIStepper* stepper = [[UIStepper alloc] init];
       stepper.frame = CGRectMake(220, 10, 100, 10);
       [cell.contentView addSubview: stepper];
   }  

   return cell; 
}

这会将步进器添加到表中每个单元格的右侧.

This will add a stepper to the right-hand side of each cell in your table.

这篇关于以编程方式在单元格内添加UiStepper的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆