in my table view, i placed a custom "Add to Favs" button in every cell to enable the user to copy the exact cell content to a second tableview controller. when you hit the "Add to Favs" button an alert view shows up to ask if you want to copy the cell and paste it to the second view controller or not. now there are two things. 1- is there a way to delete the "Add to Favs" button permanently from that cell if "OK" is selected from the alert view to indicate that the cell is copied and pasted to the second tableview? - so the user won't be able to add the cell content over and over again. 2- this is the bigger question: how would i copy and paste the cell content to the secondtableview controller with "Add to Favs" click?
here is the way my cells re configured:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
NSString* letter = [letters objectAtIndex:indexPath.section];
NSArray* arrayForLetter = (NSArray*)[filteredTableData objectForKey:letter];
Songs* songs = (Songs*)[arrayForLetter objectAtIndex:indexPath.row];
cell.textLabel.text = songs.name;
cell.detailTextLabel.text = songs.description;
CGSize itemSize = CGSizeMake(50, 50);
UIGraphicsBeginImageContextWithOptions(itemSize, NO, UIScreen.mainScreen.scale);
CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
[cell.imageView.image drawInRect:imageRect];
cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIButton *addtoFavsButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
addtoFavsButton.frame = CGRectMake(200.0f, 5.0f, 105.0f, 70.0f);
[addtoFavsButton setImage:[UIImage imageNamed:@"fav.png"] forState:UIControlStateNormal];
[addtoFavsButton setTintColor:[UIColor whiteColor]];
[cell addSubview:addtoFavsButton];
[addtoFavsButton addTarget:self
action:@selector(addtoFavs:)
forControlEvents:UIControlEventTouchUpInside];
return cell;
}
- (IBAction)addtoFavs:(id)sender
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Dikkaaaat!"
message:@"Şarkıyı Favori Akorlarınıza Alıyorsunuz..."
delegate:nil
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK", nil];
[alert show];
}
Considering the data is in the app only, and considering you are using a regular table cell, not a custom one, what I would recommend is:
Make a new simple array in your app called "myFavorites" or whatever, which will hold just a list of numerical values.
When the user confirms to add to favorites, take the current section and row indexes from the songs array, and store in this new array.
In your first view controller, add to your "cellForRowAtIndexPath" a simple check to see if the song for that row exist in the new array with.
Something like:
Your second table view will be almost identical, except near the top of your "cellForRowAtIndexPath", do a similar check:
There are other things you can do but it would require changing your setup from a regular cell to a custom cell with a new class and properties blah blah, so is a little more complicated to implement, but would still amount to practically the same output/processing.