I am trying to determine how to set UITableViewCellStyle when using new methods in iOS 6 for UITableView .
Previously, when creating a UITableViewCell I would change the enumeration of the UITableViewCellStyle to create different types of cells by default when calling initWithStyle: but from what I can collect, this is no longer the case.
Apple's documentation for a UITableView states:
Return value : A UITableViewCell object with an associated reuse identifier. This method always returns a valid cell.
Discussion : For performance reasons, a table view data source should usually reuse UITableViewCell objects when it assigns cells to rows in its tableView: cellForRowAtIndexPath: method. The table view maintains a queue or list of UITableViewCell objects that the data source is marked for reuse. Call this method from the data source object when it is asked to provide a new cell to represent the table. This method deactivates an existing cell, if available, or creates a new one based on a previously saved class or nib file.
It is important . You must register a class or nib file using the registerNib: forCellReuseIdentifier: or registerClass: forCellReuseIdentifier: method before calling this method.
If you register a class for the specified identifier and create a new cell, this method initializes the cell by calling its initWithStyle: reuseIdentifier: method. For nib-based cells, this method loads the cell object from the provided nib file. If an existing cell was reusable, this method instead calls the prepareForReuse method.
Here's what my new cellForRowAtIndexPath looks like after implementing new methods:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellIdentifier = @"cell_identifier"; [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellIdentifier]; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath]; return cell; }
The code that I still work fine, but always returns the default style. How can I change this so that I can create cells with other styles like UITableViewCellStyleDefault , UITableViewCellStyleValue1 , UITableViewCellStyleValue2 and UITableViewCellStyleSubtitle ?
I donβt want to subclass UITableViewCell , I just want to change the default type, as I could do before iOS 6. It seems strange that Apple will provide advanced methods, but with minimal documentation to support their implementation.
Has anyone dealt with this or have encountered a similar problem? I try my best to find any reasonable information.