Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 04-17-2011, 12:01 PM   #1 (permalink)
Registered Member
 
Join Date: Apr 2011
Posts: 5
Tapbits is on a distinguished road
Default UITableViewCell Subclass

I have a big problem here. I wrote a custom UITableViewCell subclass completely customized with images and labels. I also created a custom action to edit the UITableView. When tapping the button, I am trying to perform an action to a UIButton which would, when tapped delete the cell. What I have works fine if I have one cell there. Here is what I have for the button to edit the table view.

// UINavigatinBarButton
Code:
- (void)editItems:(UIButton *)button {
if (!isEditing) {
    NSLog(@"Editing...");
    isEditing = YES;

    [UIView beginAnimations:@"editButtonFlipContext" context:nil];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:cell.checkmarkImage cache:YES];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.3];
    cell.checkmarkImage.image = [UIImage imageNamed:@"data_cell_delete_button.png"];
    [UIView commitAnimations];

    [cell.checkmarkButton addTarget:self action:@selector(deleteCell:event:) forControlEvents:UIControlEventTouchUpInside];

} else {
    NSLog(@"Done Editing.");
    isEditing = NO;

    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(deleteCell:event:) object:nil];

    [UIView beginAnimations:@"editButtonFlipContext" context:nil];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:cell.checkmarkImage cache:YES];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.3];
    cell.checkmarkImage.image = [UIImage imageNamed:@"data_cell_detail_button.png"];
    [UIView commitAnimations];
}
}
and for the UIButton in the cell:

// Cell Button
Code:
- (void)deleteCell:(id)sender event:(id)event {
NSSet *touches = [event allTouches];
UITouch *touch = [touches anyObject];
CGPoint currentTouchPosition = [touch locationInView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint: currentTouchPosition];
if (indexPath != nil)
{
    NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
    [context deleteObject:[self.fetchedResultsController objectAtIndexPath:indexPath]];
}
}
It all seems to work fine on one cell like I said above, it won't make all the cells have that same action all the time, nor will it set the the correct image to it ("data_cell_delete_button.png"). If you need more info let me know. If you have any suggestions on fixing up the code for both actions I'd greatly appreciate it.

Thanks

Edit 2:
When clicking done on the navigation bar button, it doesn't remove the current @selector for the cell.checkmarkButton

Last edited by Tapbits; 04-17-2011 at 12:30 PM.
Tapbits is offline   Reply With Quote
Old 04-17-2011, 12:11 PM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

If you can't solve this for yourself, then my guess is that you don't have any business subclassing UITableView. Why are you doing that?
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 04-17-2011, 12:23 PM   #3 (permalink)
Registered Member
 
Join Date: Apr 2011
Posts: 5
Tapbits is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
If you can't solve this for yourself, then my guess is that you don't have any business subclassing UITableView. Why are you doing that?
Ahh, I remember why I never post on forums now. I did this once before, but a long time ago. I have searched the iOS reference library and couldn't find anything. I'm create a task management app which is completely customized. I have spent quite a lot of time trying to figure this out and searching for answers.
Tapbits is offline   Reply With Quote
Old 04-17-2011, 12:24 PM   #4 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Answer the question: why are you subclassing UITableView? What behavior and/or actions are you needing that you feel can only be accomplished by subclassing?
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 04-17-2011, 12:27 PM   #5 (permalink)
Registered Member
 
Join Date: Apr 2011
Posts: 5
Tapbits is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
Answer the question: why are you subclassing UITableView? What behavior and/or actions are you needing that you feel can only be accomplished by subclassing?
I just did answer it, I'm subclassing to completely customize the cell.

The behavior of it, well, when tapping the edit button, a UIButton placed on the custom cell is active to respond to a tap. When the user taps on it the cell should be deleted. That part is okay. The part that isn't working is when tapping the edit button, its not settings a particular image to the UIImageView on all the cells. Its only appearing on one of them.
Tapbits is offline   Reply With Quote
Old 04-17-2011, 12:28 PM   #6 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Subclassing UITableView and subclassing UITableViewCell are two different things. Which one do you mean? You do not have to subclass UITableView in order to have a custom cell.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 04-17-2011, 12:30 PM   #7 (permalink)
Registered Member
 
Join Date: Apr 2011
Posts: 5
Tapbits is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
Subclassing UITableView and subclassing UITableViewCell are two different things. Which one do you mean? You do not have to subclass UITableView in order to have a custom cell.
I meant a UItableViewCell, not a UITableView. I'll correct those typos
Tapbits is offline   Reply With Quote
Old 04-17-2011, 12:33 PM   #8 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Precision matters in programming.

Let the view controller worry about deleting the cells. Rig your button to talk to the view controller, and then the view controller can figure out which cell that is and delete the appropriate row.

You should be overriding setEditing:animated: in your cell subclass to achieve the behavior that you want.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 04-17-2011, 12:41 PM   #9 (permalink)
Registered Member
 
Join Date: Apr 2011
Posts: 5
Tapbits is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
Precision matters in programming.

Let the view controller worry about deleting the cells. Rig your button to talk to the view controller, and then the view controller can figure out which cell that is and delete the appropriate row.

You should be overriding setEditing:animated: in your cell subclass to achieve the behavior that you want.
Okay thanks.
Tapbits is offline   Reply With Quote
Reply

Bookmarks

Tags
cell, image, subclass, uitableview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 361
14 members and 347 guests
dansparrow, dre, ilmman, LezB44, lorrettaui53, Nobbsy, Objective Zero, oztemel, pbart, samdanielblr, shagor012, sledzeppelin, thephotographer, Trickphotostudios
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,119
Posts: 402,896
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:47 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0