lundi 27 juin 2016

how add number near name of cell

i have this:enter image description here

now i want put number(price) under all fruits..how can i do?

now i show you my code:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad


{
    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.
    arOptions = [[NSMutableArray alloc] init];
    //valore=[NSIntegerMax alloc] init];

   /* for(int i = 1; i <= 20; i++) {
        [arOptions addObject:[NSString stringWithFormat:@"Option %i", i]];
    }*/


    [arOptions addObject:@"Apple"  ];
    [arOptions addObject:@"Mango"];
    [arOptions addObject:@"Papaya"];
    [arOptions addObject:@"Guava"];
    [arOptions addObject:@"Pineapple"];
    [arOptions addObject:@"Strawberry"];
    [arOptions addObject:@"Banana"];
    [arOptions addObject:@"Grapes"];
    [arOptions addObject:@"Pomegranate"];
    [arOptions addObject:@"Green Tea"];
    [arOptions addObject:@"Raisin"];

    arSelectedRows = [[NSMutableArray alloc] init];

    UITableView *tblOptions = [[UITableView alloc] initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, self.view.frame.size.height - 50) style:UITableViewStylePlain];
    tblOptions.delegate = self;
    tblOptions.dataSource = self;
    [self.view addSubview:tblOptions];

    UIButton *btnAlert = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    btnAlert.frame = CGRectMake(20, self.view.frame.size.height - 35 + 5, self.view.frame.size.width - 20 - 20, 50 - 10);
    [btnAlert setTitle:@"Get_answer" forState:UIControlStateNormal];
    [btnAlert addTarget:self action:@selector(btnAlertTapped:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btnAlert];

}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}

-(void)btnAlertTapped:(id)sender {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"You selected" message:[[self getSelections] componentsJoinedByString:@", "] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
}

-(NSArray *)getSelections {
    NSMutableArray *selections = [[NSMutableArray alloc] init];

    for(NSIndexPath *indexPath in arSelectedRows) {
        [selections addObject:[arOptions objectAtIndex:indexPath.row]];
    }

    return selections;
}

#pragma UITableView delegate functions

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return arOptions.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *cellIdent = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdent];

    if(cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdent];
    }

    cell.textLabel.text = [arOptions objectAtIndex:indexPath.row];
    if([arSelectedRows containsObject:indexPath]) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
    else {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }

    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if(cell.accessoryType == UITableViewCellAccessoryNone) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
        [arSelectedRows addObject:indexPath];
    }
    else {
        cell.accessoryType = UITableViewCellAccessoryNone;
        [arSelectedRows removeObject:indexPath];
    }
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}


@end

THANKS everybody in advance!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

I hope that you can help me!

Aucun commentaire:

Enregistrer un commentaire