Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Aug 30, 2009, 11:45 AM   #1
Darkroom
Guest
 
Join Date: Dec 2006
Location: Montréal, Canada
Custom Delete For Custom UITableViewCell *solved*

the visual design of my custom table view doesn't accommodate apple's built-in delete editing style. therefore, i'm attempting to create my own delete function.

within the custom cell's nib, i've created a custom delete UIButton that will become visible when the user enters my app's table view delete mod. the image of the delete button is 22x22, but the actual button has a greater size to make touching easier. the first thing i've noticed is that these buttons are very difficult to press. if i make the button larger, the cells seem to get confused (pressing the delete button on the first cell activates the delete on the 2nd cell). interestingly, this seems to only occur if my custom delete button is located at the very right edge of my custom cell. move it to the right appears to solve the issue. moving on.

from my custom cell class, i've added an IBOutlet to the tableView's delegate and an IBAction for the delete button, and wired up the connection in IB:

Code:
#import <UIKit/UIKit.h>
@class TableViewDelegate;

@interface CustomCell : UITableViewCell
	{
	TableViewDelegate *tableViewDelegateClass;
	UILabel *label1;
	UILabel *label2;
	UIButton *deleteButton;
	}
	
@property (nonatomic, retain) IBOutlet UILabel * label1;
@property (nonatomic, retain) IBOutlet UILabel * label2;
@property (nonatomic, retain) IBOutlet UIButton *deleteButton;

- (IBAction)deleteButton:(id)sender atIndexPath:(NSIndexPath *)indexPath;

@end

#import "CustomCell.h"
#import "TableViewDelegate.h"

@implementation SizeMeMeasurementsCell
@synthesize label1, label2, deleteButton;


- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier
	{
	if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier])
		{
		// Initialization code
		}
	return self;
	}
	
- (IBAction)deleteButton:(id)sender atIndexPath:(NSIndexPath *)indexPath
	{
	NSLog(@"Action Triggered");
	[tableViewDelegateClass deleteTableViewCell:indexPath];
	}

- (void)dealloc
	{
	[label1 release];
	[label2 release];
	[deleteButton release];
	[super dealloc];
	}

@end
so now in my tableViewDelegate class, my deleteTableViewCell method currently looks like this:

Code:
- (void)deleteTableViewCell:(NSIndexPath *)indexPath
	{
	NSLog(@"Message Received From Custom Cell");
	NSUInteger row = [indexPath row];
	[self.listDataArray removeObjectAtIndex:row];
	[self.myTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
	}
first problem: the deleteTableViewCell method is not receiving the message from the custom cell class. I'm assuming this is due to an error on my part, and i'm hoping it's not because my custom cell's XIB bypasses the use File's Owner as it's just a subclass of UITableViewCell. if this is the case, i hope there is a simple solution.

because my connections aren't working, i can't test the affectiveness of my deleteTableViewCell:(NSIndexPath *)indexPath method. in this method i'm removing the objects at index path, both from the table view and the data source. i'm not sure if i'm also to update the tableView/data source in this method, or if it's automatic, but that should be easy enough to figure out.

so. why is my table view delegate class not receiving the message from my UITableViewCell subclass, and does my deleteTableViewCell:(NSIndexPath *)indexPath appear to be correct?

Last edited by Darkroom; Aug 30, 2009 at 07:52 PM.
Darkroom is offline   0 Reply With Quote
Old Aug 30, 2009, 01:34 PM   #2
Darkroom
Thread Starter
Guest
 
Join Date: Dec 2006
Location: Montréal, Canada
connections now work. i just added a proxy object representing my tableView delegate class, and connected the delete buttons to a method located there.

Code:
- (IBAction)deleteMeasurement:(id)sender atIndexPath:(NSIndexPath *)indexPath
	{
	NSLog(@"Message From Custom Cell Received");
	NSUInteger row = [indexPath row];
	[self.listDataArray removeObjectAtIndex:row];
	[self.myTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
	}
this code is throwing an exception. problem with NSIndexPath. how can i pass the indexPath of the delete button from the custom UITableViewCell class to it's delegate?
Darkroom is offline   0 Reply With Quote
Old Aug 30, 2009, 07:45 PM   #3
Darkroom
Thread Starter
Guest
 
Join Date: Dec 2006
Location: Montréal, Canada
solved:

1. Custom cell XIB is composed of a UIButton (and some UILabels), within a UIView, placed in the custom cell window.
2. An External Object replaces the File's Owner proxy (just delete it), and set to represent the class that is the UITableView's delegate.
3. The UIButton's touchUpInside (or whatever you want) is connected to the proxy object's IBAction (the following method) within UITableView's delegate class.

Code:
- (IBAction)deleteMeasurement:(id)sender
	{
	NSLog(@"Message From Custom Cell Received");
	NSIndexPath *indexPath = [self.myTableView indexPathForCell:(UITableViewCell *)[[[sender superview] superview] superview]];
	NSUInteger row = [indexPath row];
	[self.myDataArray removeObjectAtIndex:row];
	[self.myTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
	}
Darkroom is offline   0 Reply With Quote
Old Nov 15, 2010, 08:32 AM   #4
greacher
macrumors newbie
 
Join Date: Jan 2008
I followed your instructions, and the delete method still isn't firing.
Did you have to do anything special when you loaded the nib, like using the options: parameter?

Code:
		NSDictionary *proxy = [NSDictionary dictionaryWithObject:self forKey:@"cellProxyKey"];
		NSDictionary *options = [NSDictionary dictionaryWithObject:proxy forKey:UINibExternalObjects];
		NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:nil options:options];
greacher is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
custom UITableViewCell subview frame erdinc27 iPhone/iPad Programming 5 May 21, 2014 01:21 AM
Resolved: custom font for Custom UITableViewCell erdinc27 iPhone/iPad Programming 5 Apr 18, 2014 12:50 PM
Solved: Word 2011 - Can't use custom page setup joejoejoe Mac Applications and Mac App Store 2 Apr 2, 2014 09:04 PM
Springtomize 2 Custom Time Mode - Custom String GUILTIE Jailbreaks and iOS Hacks 10 Mar 7, 2013 03:18 PM
Custom Delete UITableViewCell mdhansen5 iPhone/iPad Programming 1 Jun 1, 2012 10:41 AM

Forum Jump

All times are GMT -5. The time now is 12:17 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC