I want to get the some of the data of what is displayed in a cell when I'm tapping on a button which I placed in the cell. For this I have implemented used the indexPathForSelectedRow method. But when I'm tapping on the cell, the method is returning 0 index, even if I'm not tapping on the 0th index cell. This is the code I used for the button -
- (IBAction)dataSaveLounge:(id)sender {
NSIndexPath *path = [self.loungeTable indexPathForSelectedRow];
NSString *titleSave = [[loungeData objectAtIndex:path.row] valueForKey:@"title"];
NSString *subtitleSave = [[loungeData objectAtIndex:path.row] valueForKey:@"excerpt"];
NSString *idSave = [[loungeData objectAtIndex:path.row] valueForKey:@"id"];
saveMdl = [FavouritesModel saveFavourites:titleSave and:subtitleSave and:idSave];
}
EDIT : Added cellfForRowAtIndex Method
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *loungeCellID = @"MyCellLounge";
LoungeTableCell *loungeCell = [tableView dequeueReusableCellWithIdentifier:loungeCellID];
if (loungeCell == nil) {
loungeCell = [[LoungeTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyCellLounge"];
}
loungeCell.loungeTitle.text = [[loungeData objectAtIndex:indexPath.row]valueForKey:@"title"];
loungeCell.loungeSubtitle.text = [[loungeData objectAtIndex:indexPath.row]valueForKey:@"excerpt"];
dispatch_async(dispatch_get_main_queue(), ^{
loungeCell.loungeImgView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"default"]];
[loungeCell.loungeImgView sd_setImageWithURL:[NSURL URLWithString:[[loungeData objectAtIndex:indexPath.row] valueForKey:@"banner_image"]]];
});
return loungeCell;
}
I'm saving some data in core data on button click, hence the last method call