Iphone Uisteper没有出现

Iphone Uisteper没有出现,iphone,ios,cocoa-touch,uitableview,Iphone,Ios,Cocoa Touch,Uitableview,我试图以编程方式添加UIStepper,下面是我的代码:步进器不会出现: stepper = [[UIStepper alloc]init]; [stepper setFrame:CGRectMake(216, 91, 155, 25)]; [stepper setMinimumValue:0]; [cell addSubview:stepper]; 谢谢大家! CELLFORROWATINDEXPATH: - (UITableViewCell

我试图以编程方式添加UIStepper,下面是我的代码:步进器不会出现:

     stepper =  [[UIStepper alloc]init];
     [stepper setFrame:CGRectMake(216, 91, 155, 25)];
     [stepper setMinimumValue:0];
     [cell addSubview:stepper];
谢谢大家!

CELLFORROWATINDEXPATH:

    - (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;
}
返回单元格正上方的
if
语句只是在单元格上放置一些标签

[cell.contentView addSubview:stepper];
编辑: 在代码中,您有:

 [stepper setFrame:CGRectMake(216, 91, 155, 25)];
然而你声称你的手机高73像素,宽320像素

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

在91的y处出现的步进器位于单元视图之外

试试这个:

[stepper setFrame:CGRectMake(216, 22, 100, 30)];
编辑: 在代码中,您有:

 [stepper setFrame:CGRectMake(216, 91, 155, 25)];
然而你声称你的手机高73像素,宽320像素

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

在91的y处出现的步进器位于单元视图之外

试试这个:

[stepper setFrame:CGRectMake(216, 22, 100, 30)];

ios 5.0中引入了UIStepper控件。您需要检查是否在ios 5.0以下使用它

更多参考资料:-


ios 5.0中引入了UIStepper控件。您需要检查是否在ios 5.0下使用它

更多参考资料:-


使用
initWithFrame:
,当以编程方式实例化属于
UIView
子类的类时,该类是指定的初始值设定项

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

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

-(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”行中有一个步进器。

使用
initWithFrame:
,当以编程方式实例化属于
UIView
子类的类时,它是指定的初始值设定项

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

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

-(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;
}


对我来说,此代码显示默认项目表,“详细信息”行中有一个步进器。

告诉我们有关单元格的详细信息。告诉我们有关单元格的详细信息。无效:(这和我的设置框有关系吗:CGRect?谢谢你的单元格有多大?这个框在单元格的范围内吗?@ThomasW高度是73像素,宽度是320像素!!@iProRage,请看我的编辑。你在单元格外显示了步进器…@DanielAmitay好的,我试过了,但还是没有显示出来。)向上:(我不知道为什么不会。我运行了一个新项目,效果很好。它显示得非常完美,但是当我将完全相同的代码添加到
cellForRow
方法中时,它不会显示在这个应用程序中。我在我的问题中添加了我所有的
cellForRow
。请您查看一下,看看是否有任何问题。谢谢您的帮助。)elp!!不起作用:(这和我的设置框有关系吗:CGRect?谢谢你的单元格有多大?这个框在单元格的范围内吗?@ThomasW高度是73像素,宽度是320像素!!@iProRage,请看我的编辑。你在单元格外显示了步进器…@DanielAmitay好的,我试过了,但还是没有显示出来。)向上:(我不知道为什么不会。我运行了一个新项目,效果很好。它显示得非常完美,但是当我将完全相同的代码添加到
cellForRow
方法中时,它不会显示在这个应用程序中。我在我的问题中添加了我所有的
cellForRow
。请您查看一下,看看是否有任何问题。谢谢您的帮助。)elp!!谢谢你的回复,不过我添加了这一行并删除了我的
stepper=[[UIStepper alloc]init]
声明。它仍然拒绝显示!你知道这是为什么吗?Thanksim抱歉,它不是44px高,我很笨,在interface builder中,我将高度设置为73,而不是43哈哈,该死的人!!:/我按照你上面提到的方法修改了代码,并修改了坐标。它仍然不会显示!在代码
NSLog之前插入这个(@“单元格是:%@”,cell);
好的,我知道了,控制台说:
单元格是:
谢谢你的回复,但是我添加了这一行并删除了我的
步进器=[[UIStepper alloc]init]
declaration。它仍然拒绝出现!你知道为什么吗?Thanksim抱歉,它不是44px高,我很笨,在interface builder中,我将高度设置为73,而不是43。哈哈,该死的人!!:/我按照你上面提到的方法修改了代码,并修改了坐标。它仍然不会出现!在代码
NSLog(@)之前插入这个单元格是:%@,cell);
好的,我知道了,控制台说:
单元格是: