Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7087307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:39:29+00:00 2026-05-28T07:39:29+00:00

I have used custom cell in my tableview for different values and to save

  • 0

I have used custom cell in my tableview for different values and to save value into core data I have used UILongPressGestureRecognizer, so that when user presses the cell for long then a dialogue box will be opened giving user the option to add the value of that specific cell into core data.

My code for this is :

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    NSString * cellValue;
    if (tableView == listTable) 
    {
       cellValue = [listVehicles objectAtIndex:indexPath.row];
    } 
    else // handle search results table view
    { 
        cellValue = [filteredListItems objectAtIndex:indexPath.row];
    }

    static NSString *CellIdentifier = @"vlCell";

    VehicleListCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) 
    {
        NSLog(@"Cell Created");

        NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:@"VehicleListCell" owner:nil options:nil];

        for (id currentObject in nibObjects) {
            if ([currentObject isKindOfClass:[VehicleListCell class]]) {
                cell = (VehicleListCell *)currentObject;
            }
        }

        UILongPressGestureRecognizer *pressRecongnizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(tableCellPressed:)];
        pressRecongnizer.minimumPressDuration = 0.5f;
        [cell addGestureRecognizer:pressRecongnizer];
        [pressRecongnizer release];
    }

    cell.textLabel.font = [UIFont systemFontOfSize:10];

    [[cell ignition] setImage:[UIImage imageNamed:@"ignition.png"]];
    [[cell direction] setImage:[UIImage imageNamed:@"south.png"]];

    cell.licPlate.text = cellValue;

    return cell;
}

for longpressgesture:

- (void)tableCellPressed:(UILongPressGestureRecognizer *)recognizer {

    UITableViewCell *cell = (UITableViewCell *) [recognizer view];
    NSString *text = cell.textLabel.text;

    NSLog(@"cell value: %@", text);

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles: nil] ;

    [alert addButtonWithTitle:@"Add to Favourites"];
    [alert addButtonWithTitle:@"Take to Map"];

    [alert show];
}


-(void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex {

    NSString *title = [alert buttonTitleAtIndex:buttonIndex];

    if([title isEqualToString:@"Add to Favourites"])
    {
        NSLog(@"Added to favourites.");
    }
    else if([title isEqualToString:@"Take to Map"])
    {
        NSLog(@"Go to MapView");
    }
}

Now the issue is that if I click on any cell I am getting the only one cell’s value.

How can I get the value of each cell by pressing on it and then save it to core data ?

EDITED:

I have created a view controller with xib file for custom cell:

its .h file is as:

@interface VehicleListCell : UITableViewCell{

IBOutlet UILabel *licPlate;
IBOutlet UILabel *commDate;

IBOutlet UIImageView *ignition;
IBOutlet UIImageView *direction;

IBOutlet UITableViewCell *cell;
}

@property (nonatomic, strong) IBOutlet UILabel *licPlate;
@property (nonatomic, strong) IBOutlet UILabel *commDate;
@property (nonatomic, strong) IBOutlet UIImageView *ignition;
@property (nonatomic, strong) IBOutlet UIImageView *direction;

@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:39:30+00:00Added an answer on May 28, 2026 at 7:39 am

    I’m not sure how do you setup your VehicleListCell, but it might have different property than normal UITableView, so change your

    UITableViewCell *cell = (UITableViewCell *) [recognizer view];
    

    in

    - (void)tableCellPressed:(UILongPressGestureRecognizer *)recognizer
    

    to

    VehicleListCell* cell = (VehicleListCell *)[recognizer view];
    

    edit

    try this code

    - (void)tableCellPressed:(UILongPressGestureRecognizer *)recognizer {
    
        VehicleListCell* cell = (VehicleListCell *)[recognizer view];
        NSString *text = cell.licPlate.text;
    
        NSLog(@"cell value: %@", text);
    
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles: nil] ;
    
        [alert addButtonWithTitle:@"Add to Favourites"];
        [alert addButtonWithTitle:@"Take to Map"];
    
        [alert show];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following cell which is used for my custom column data type
I have a custom UITableViewCell that I use like this: AppTableCell *cell = [tableView
I have built a custom membership provider that I have used in a previous
I have a custom DataGridViewCell with a user-control as its editing control. The cell
I have a custom EditButton that shows a dialog for the user to select
I have an table view where i am loaded custom cell from different nib,
I have a custom UIbutton in every cell of my tableview. This UIbutton works
I have used custom cell class for my uitableview and used in cellForRowAtIndexPath method.
I have a custom cell that contains a button in a table view. The
I have a custom UITableView cell that sports an Image, and a headline. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.