Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show selected cell value from uitable view as label in other view

Im new to iphone development.I have a tableview controller i want to show selected(multiple) cell(checkmarked) value as a lables in other view,How can i acheive this?this is the code which i usd for check marking the tableview cell

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

UITableViewCell *thisCell = [tableView cellForRowAtIndexPath:indexPath];
if (thisCell.accessoryType == UITableViewCellAccessoryNone) {
    thisCell.accessoryType = UITableViewCellAccessoryCheckmark;

}else
{
    thisCell.accessoryType = UITableViewCellAccessoryNone;
}
}
- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellAccessoryNone;
}
like image 907
iosdev Avatar asked Dec 22 '25 00:12

iosdev


1 Answers

Add the Checkmarked Cell's index in an array and Display the value at that index in Label

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *thisCell = [tableView cellForRowAtIndexPath:indexPath];
    if (thisCell.accessoryType == UITableViewCellAccessoryNone) {
        thisCell.accessoryType = UITableViewCellAccessoryCheckmark;
        [myIndexArray addObject:[NSString stringWithFormat:@"%d",indexPath.row]];
    }
    else
    {
        thisCell.accessoryType = UITableViewCellAccessoryNone;
        for(int i=0; i<myIndexArray.count; i++)
        {
            if([[myIndexArray objectAtIndex:i]intValue]== indexPath.row)
            {
                [myIndexArray removeObjectAtIndex:i];
                 break;
            }
        }
    }
}
like image 93
Suresh Varma Avatar answered Dec 23 '25 15:12

Suresh Varma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!