0

可能重复:
如何获取辅助检查单元格值并将其显示在 alertview
how-to-get-accessarychecked-cell-value-and-show-it-on-alertview

我已创建UITableView并已cellUITableViewaccessarychecked 中。我已经实施了一个名为 -(IBAction) checkBoxClicked.

我需要的是,我想在 Alertbox 单击按钮时显示辅助检查的单元格值,这是我编写的代码:

#import "ViewController.h"

@implementation ViewController
@synthesize  cell;
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 7;
}

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

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

    cell.textLabel.text = [myarray objectAtIndex:indexPath.row];


    /*
    NSString *imagefile = [[NSBundle mainBundle] pathForResource:@"cellimage" ofType:@"png"];

    UIImage *ui = [[UIImage alloc] initWithContentsOfFile:imagefile];

    cell.imageView.image = ui;*/

    NSString *check = [[NSBundle mainBundle] pathForResource:@"checkbox_not_ticked" ofType:@"png"];

    UIImage *bi = [[UIImage alloc] initWithContentsOfFile:check];

    cell.imageView.image = bi;
    cell.accessoryType = UITableViewCellAccessoryNone;

       return cell; 


    [cell release];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

     cell = [tableView cellForRowAtIndexPath:indexPath];

    if (cell.accessoryType == UITableViewCellAccessoryNone) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;

    } else {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }

}
-(IBAction) checkBoxClicked
{
NSArray *array = [[NSArray alloc] initWithArray:[myarray objectAtIndex:cell.accessoryType]:UITableViewCellAccessoryCheckmark];

    if (array.cell.accessoryType == UITableViewCellAccessoryCheckmark)
{

UIAlertView *msg = [[ UIAlertView alloc] initWithTitle:@"selected items are given: " message:array delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil ];

    [msg show ];
    [msg release];
    [myarray release];

    }
}

//-(IBAction)checkBoxClicked{}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    myarray = [[NSArray alloc] initWithObjects:@"mondey",@"tuesday",
@"wednesday",@"thursday",@"friday",@"saturday",@"sundey", nil];

    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

}

- (void)viewDidUnload
{
    [myarray release];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end
4

1 回答 1

-1

Use tag for each button and retrieve the button instance

于 2012-10-25T05:09:40.680 回答