Welcome, Guest
Username Password: Remember me
  • Page:
  • 1

TOPIC: Cell as a button?

Cell as a button? 1 year, 8 months ago #1

I have a table view that I use for editing a certain object which represents a football match. It has a few properties, and then it has two cells where the user should be able to select a team. I'm thinking when they click the button I want to push a new view controller where the user can select an existing team or create a new one.

Right now I have this code:
 
SCTableViewCell *cell;
cell = [SCTableViewCell cellWithText: @"Home Team"];
cell.boundKey = @"homeTeam";
cell.delegate = self;
[teamSec addCell: cell];
cell = [SCTableViewCell cellWithText: @"Away Team"];
cell.boundKey = @"awayTeam";
cell.delegate = self;
[teamSec addCell: cell];
 


But when the didSelectCell: method is called, I'm not sure how to best differentiate the cells.

What would be the best way to solve this?

I guess what would be nice was to have a cell that could call a specific selector when selected.
  • skyfex
  • OFFLINE
  • Fresh Boarder
  • Posts: 15
  • Karma: 1

Re: Cell as a button? 1 year, 8 months ago #2

I'm going to answer myself and say that perhaps subclassing SCTableViewCell with SCDateCell as an example is the best idea. I'd still love some input though.
  • skyfex
  • OFFLINE
  • Fresh Boarder
  • Posts: 15
  • Karma: 1

Re: Cell as a button? 1 year, 8 months ago #3

You can use either the SCTableViewModelDelegate tableViewModel:didSelectRowAtIndexPath: method, or the SCTableViewCellDelegate didSelectCell: method.

Also, please watch www.sensiblecocoa.com/video-tutorials/wa...iew-replacement.html for a tutorial on how to achieve this.

Hope this helps
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72

Re: Cell as a button? 1 year, 8 months ago #4

The problem with those methods was assigning arbitrary data to the cell, using the cell title to differentiate the cells seemed hacky. Subclassing has worked out alright though.
  • skyfex
  • OFFLINE
  • Fresh Boarder
  • Posts: 15
  • Karma: 1

Re: Cell as a button? 1 year, 8 months ago #5

Using tableViewModel:didSelectRowAtIndexPath:, you can differentiate cells using the indexPath parameter. Furthermore, you can differentiate cells through setting their "tag" property (inherited from UIView).
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72

Re: Cell as a button? 1 year, 8 months ago #6

Right, I had been using indexPath when using UITableViewController before, so I'm not sure why I didn't think of that. I guess I changed mindset to the SensibleTableView mindset too fast
  • skyfex
  • OFFLINE
  • Fresh Boarder
  • Posts: 15
  • Karma: 1
  • Page:
  • 1
Time to create page: 1.04 seconds