ios - A smart way to configure custom cells on table load-up? -


I have a table view with about 5 different custom cells, which are designed in the storyboard.

Each of these cells has its own dedicated subclass of UITableViewCell . cellForRowAtIndexPath , I dequeue cells:

  UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: self.cellArray [indexPath.row] forIndexPath: indexPath];   

The problem now is, I want to call configureCell for each of these cells have declared this method in my other custom cell classes and implemented but the problem is that XCode throws up a warning when I do these cells with respect to not put in their respective classes in the cells, because XCode UITableViewCell cells.

It is possible to cast each cell type individually, but with lots of if and else if lines, what is verbose do A clever way, maybe a method configureCell ?

Of course, more flexible than I think this sub-Clasing with a protocol, but It depends on the words of each cell class, and you can always mix and match in both ways.

  @protocol CellX - Configure (zero): (id) information; @ And @ interfaces cell a: uitable vixel & lt; Cellx & gt; @and @InterfaceSellb: UITTable Wexels & lt; Cellx & gt; @end   

In the cell creation method:

  NSString * identifier = / * index and whatnot * / id & lt; CellX & gt; Cell = (id & lt; cellX & gt;) [tableview dequeueReusableCellWithIdentifier: & lt; # Identifier # & gt; ForIndexPath: indexPath]; / * The cell class can be either cell or cellB, which is the selected identifier * / [cell configured: & lt; # Data # & gt;]; In addition to the configuration method, you can add any asset to the protocol that is shared in the cell (like  kind ,  status  etc., whatever you use to deal with cells).   

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -