I have a button which when clicked shows a popover with a table view which is showing some list of data.
On selection of a table view row, I want to show a check mark on the right hand side of the cell, but the code is not working. Can someone help me to diagnose this?
The same code is working well if I use only a normal tableview instead of popover table view.
Currently i am using XCode 5.1.1 , iOS7.1 , iPad Simulator.
//@property (assign,nonatomic)int selectedIndex;
//@property (strong,nonatomic)NSMutableArray *listArray;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.listArray=[[NSMutableArray alloc]initWithObjects:@"1",@"2",@"3", nil];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.listArray count];
}
- (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];
}
// Configure cell now
cell.textLabel.text = [self.listArray objectAtIndex:indexPath.row];
if(indexPath.row == self.selectedIndex)
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
self.selectedIndex = indexPath.row;
[tableView reloadData];
}
//For Button Action Method
- (IBAction)buttonAction:(id)sender {
UIButton *button = (UIButton*)sender;
TableViewController *tableViewController = [[TableViewController alloc] initWithNibName:@"TableViewController" bundle:nil];
self.popover = [[UIPopoverController alloc] initWithContentViewController:tableViewController];
[self.popover presentPopoverFromRect:[sender bounds] inView:button permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
}