Re: Design for custom tableviewcell button action
Re: Design for custom tableviewcell button action
- Subject: Re: Design for custom tableviewcell button action
- From: Brian Slick <email@hidden>
- Date: Fri, 03 Jul 2009 14:54:43 -0400
Well, at first I really liked this technique, and it seems simple
enough. I restructured my program to use it, and in the simulator all
went well. Then I uploaded to the phone (1st-gen) and saw absolutely
horrid scrolling performance. I fired up the CA tool, and saw numbers
that were well under 10 FPS, usually around 4.
I did make a slight adjustment to the technique - most significantly
the omitting of the identifier in the XIB file, because I have a few
different display options that hide various aspects of my cell -
because I wasn't getting the flexibility I wanted. In order to
determine if my changes were causing a problem, I built the
TaggedLocations example, and also ran it on the phone with the CA
tool. Similar numbers, similarly horrid scrolling performance.
Rebooting the phone didn't seem to make a difference for either program.
I flipped on the "Color Blended Layers" toggle for both programs, to
see if there were any key differences. My UIButton image has a
transparent background, so that lit up, but that has been the case all
along, and I had decent scrolling performance before. The primary
event name label in the TaggedLocations example lit up. 1 field in
each case, although in terms of number of pixels the TaggedLocations
program is even worse than mine.
So, if TaggedLocations was flying while mine was sucking, I'd probably
concede that what I was doing was wrong (and would probably need more
custom cells). But since neither one is performing very well, and I
can't find any significant differences between them, I'm thinking
there is either a flaw with this approach, or my trusty 1st-gen just
isn't bringing enough horsepower to handle it.
For now, I think I'll just go back to code-only cells, although if
there are any thoughts about what the problem is and/or what I can do
about it, I'd be interested in hearing them.
Brian
On Jun 26, 2009, at 9:08 PM, mmalc Crawford wrote:
Replicated content
------------------
If you replicate a cell within a table view, then (assuming you want
to use a nib file) the cell must go in a separate nib file so that
you can load it an arbitrary number of times, as discussed here: <https://devforums.apple.com/thread/3469?start=0&tstart=0
>
To summarise the general approach, though, with a particular
implementation:
In your table view controller class, declare an outlet for the
custom cell and an action method for the button:
@property (nonatomic, assign) IBOutlet <#Your table view cell class#>
*<#cell outlet property#>;
- (IBAction)<#button action#>:(UIButton *)sender;
In your table view cell class, declare an outlet for the button (and
any other UI elements as appropriate):
@property (nonatomic, retain) IBOutlet UIButton *<#button property#>;
In the cell's nib file:
The class of the File's Owner should be your table view controller
class.
Set an identifier for the cell.
Connect the appropriate outlet from File's Owner to the cell
Connect the button's action to the File's Owner
Connect the cell's button outlet to the button
In your table view controller subclass, then implement the
tableView:cellForRowAtIndexPath: method along the following lines:
// Simplified code example
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"<#your cell's idenitifier#>";
<#Your table view cell class#> *cell = (<#Your table view cell
class#> *)
[tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"<#Your nib file name#>"
owner:self options:nil];
cell = <#cell outlet property#>;
self.<#cell outlet property#> = nil;
}
cell.<#button property#>.tag = indexPath.row;
// implementation continues...
In your implementation of the action method, you can ask the button
for its tag (which will indicate the row with which it's associated).
- (IBAction)<#button action#>:(UIButton *)sender {
NSInteger row = sender.tag;
For an example that illustrates several aspects of this approach, see:
<http://developer.apple.com/iphone/library/samplecode/TaggedLocations/index.html
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden