UIStepper not showing up

im trying to add a UIStepper programmatically, HEre is my code: the stepper wont show up. :

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

Thank you!

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

the if statements right above return cell; is just to position a few labels i have on the cell.

Answers


[cell.contentView addSubview:stepper];

EDIT: In your code, you have:

 [stepper setFrame:CGRectMake(216, 91, 155, 25)];

Yet you claim that your cell is 73px tall and 320px wide.

Currently, you are setting the stepper to be 155px wide, 25px tall, at an x origin of 216 and a y origin of 91.

The stepper, appearing at y of 91 is outside of the view of the cell.

Try this:

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

Use initWithFrame:, that is the designated initializer when instantiating a class that is a subclass of UIView programmatically.

So: (adjusting frame for standard 44 points high cell)

stepper =  [[UIStepper alloc]initWithFrame:CGRectMake(206, 8, 94, 27)];

I'm not sure why it's still not showing up for you. To test the code I created a new Xcode project of type "Master/Detail" targeted for iPhone, then the only thing I did was to change the tableView:cellForRowAtIndexPath: method like so.

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

For me this code shows the default project table and the "Detail" row has a stepper in it.


Need Your Help

Search DB (of businesses) by location

mysql ruby-on-rails database database-design geolocation

I'm designing a MySQL database and a corresponding RoR app that will hold various businesses, each business will have an address.

StackOverflow while setting ListView.ItemsSource

c# wpf stack-overflow

So I have a simple struct Point with two doubles X and Y. I calculate an array of about three hundred of them and set that array as ItemsSource for a ListView in WPF. That call eventually throws a

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.