首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIStepper未显示

UIStepper未显示
EN

Stack Overflow用户
提问于 2011-12-02 10:45:50
回答 3查看 1.4K关注 0票数 1

我正在尝试以编程方式添加一个UIStepper,HEre是我的代码: stepper不会出现。:

代码语言:javascript
复制
     stepper =  [[UIStepper alloc]init];
     [stepper setFrame:CGRectMake(216, 91, 155, 25)];
     [stepper setMinimumValue:0];
     [cell addSubview:stepper];

谢谢!

CELLFORROWATINDEXPATH:

代码语言:javascript
复制
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

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

         UIStepper * myStepper =  [[UIStepper alloc]initWithFrame:CGRectMake(206,20,94,27)];
         [myStepper setMinimumValue:0];
         [cell addSubview:myStepper];

         cellLabel = [[UILabel alloc]init];
         [cellLabel setFrame:CGRectMake(65, 22, 27, 27)];
         [cellLabel setText:@"1"];
         [cell.contentView addSubview:cellLabel];
    } 
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    cell.imageView.image = [imageArray objectAtIndex:indexPath.row];    
   // cell.textLabel.text = [cells objectAtIndex:indexPath.row];
    if ([cell.imageView.image  isEqual:[UIImage imageNamed:@"paddle5.png"]]) {
        [cellLabel setFrame:CGRectMake (175, 22, 30, 30)];
    }
    if ([cell.imageView.image  isEqual:[UIImage imageNamed:@"paddle4.png"]]) {
        [cellLabel setFrame:CGRectMake (150, 22, 30, 30)];
    }
    if ([cell.imageView.image  isEqual:[UIImage imageNamed:@"paddle3.png"]]) {
        [cellLabel setFrame:CGRectMake (120, 22, 30, 30)];
    }
    if ([cell.imageView.image  isEqual:[UIImage imageNamed:@"paddle2.png"]]) {
        [cellLabel setFrame:CGRectMake (90, 22, 30, 30)];
    }
return cell;
}

return cell;上面的if语句只是用来定位单元格上的几个标签。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-12-02 12:06:05

代码语言:javascript
复制
[cell.contentView addSubview:stepper];

编辑:在您的代码中,您拥有:

代码语言:javascript
复制
 [stepper setFrame:CGRectMake(216, 91, 155, 25)];

然而,你声称你的单元格有73px高,320px宽。

当前,您正在将步进器设置为155px宽,25px高,x原点为216,y原点为91。

步进器出现在y= 91的位置,在单元格的视图之外。

试试这个:

代码语言:javascript
复制
[stepper setFrame:CGRectMake(216, 22, 100, 30)];
票数 2
EN

Stack Overflow用户

发布于 2011-12-02 15:32:21

使用initWithFrame:,这是以编程方式实例化作为UIView子类的类时指定的初始值设定项。

So:(调整标准44点高单元格的框架)

代码语言:javascript
复制
stepper =  [[UIStepper alloc]initWithFrame:CGRectMake(206, 8, 94, 27)];

我不知道为什么它还没有出现在你面前。为了测试代码,我创建了一个新的Xcode项目,类型为"Master/Detail“,目标是iPhone,然后我所做的唯一一件事就是像这样修改tableView:cellForRowAtIndexPath:方法。

代码语言:javascript
复制
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        UIStepper *stepper = [[UIStepper alloc]initWithFrame:CGRectMake(206, 8, 94, 27)];
        [stepper setMinimumValue:0];
        [cell addSubview:stepper];
    }
    // Configure the cell.
    cell.textLabel.text = NSLocalizedString(@"Detail", @"Detail");
    return cell;
}

对于我来说,这段代码显示了默认的项目表,"Detail“行中有一个stepper。

票数 2
EN

Stack Overflow用户

发布于 2011-12-02 15:14:18

IOS5.0中引入了UIStepper控件,.you需要检查您是否在iOS5.0下使用它。

如需更多参考资料:

UIStepperControlExample

UIStepperControlAppleDocumentation

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8351180

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档