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

UIStepper不显示
EN

Stack Overflow用户
提问于 2013-06-16 05:26:32
回答 2查看 361关注 0票数 0

我基本上和this question有同样的问题。但是你猜怎么了?这个问题没有任何好的答案。

代码语言:javascript
复制
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    if([indexPath row] == 0){

        UITableViewCell* aCell = [tableView dequeueReusableCellWithIdentifier:@"SwitchCell"];
        if( aCell == nil ) {
            aCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"SwitchCell"];
            aCell.textLabel.text = @"Colors";
            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];
            */
            UIStepper *stepperView = [[UIStepper alloc] initWithFrame:CGRectZero];
            NSLog(@"The stepper is %@", stepperView);
            aCell.accessoryView = stepperView;
           [stepperView setMaximumValue:10];
           [stepperView setMinimumValue:0];
           [stepperView addTarget:self action:@selector(stepperChanged) forControlEvents:UIControlEventValueChanged];
           NSLog(@"The stepper is %@", stepperView);
       }
       return aCell;
    }

    UITableViewCell *aCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"SwitchCell"];

    NSString *s = @"foo";
    s = [s stringByAppendingFormat:@"%d", [indexPath row]];
    aCell.textLabel.text = s;

return aCell;

}

因此,如果我将代码切换到注释掉的代码,就可以正常工作(显示UISwitch)。所以我想做的就是用UIStepper替换UISwitch,但它就是不显示。我讨厌objective-c。

哦,这两个打印行都显示值为(null)。在我创建它之后,它是空的吗?

编辑: iOS 5.0。我觉得答案可能与为什么会这样有关:

代码语言:javascript
复制
NSLog(@"%@", [[UISwitch alloc] init]);

is not null while

代码语言:javascript
复制
NSLog(@"%@", [[UIStepper alloc] init]);

为空。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-06-16 06:26:34

代码是在iOS 5.0中编译的,但模拟器是针对iPhone 4.3的。所以iPhone不知道UIStepper是什么,但知道UISwitch是什么。为什么它没有导致它崩溃(这可以为我节省很多时间)是一个谜。

票数 0
EN

Stack Overflow用户

发布于 2013-06-16 05:33:58

尝试通过以下方法创建UIStepper:

代码语言:javascript
复制
UIStepper* stepper = [[UIStepper alloc] init];
stepper.frame = CGRectMake(220, 10, 100, 10);
[cell.contentView addSubview: stepper];

这将把步进器放在表格视图单元格的右侧。

我找到了这个答案in this related question

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

https://stackoverflow.com/questions/17128048

复制
相关文章

相似问题

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