Add UiStepper programmatically inside cells

我只是一个虾纸丫 提交于 2020-01-07 02:33:06

问题


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

Thanks

Luca


回答1:


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.



来源:https://stackoverflow.com/questions/8522895/add-uistepper-programmatically-inside-cells

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!