Current location - Quotes Website - Personality signature - How to define an empty cell
How to define an empty cell
when using UIViewTable, we often find that the basic UITableViewCell can't meet all our needs, especially the personalized needs.

so how to create your own personalized cell through XIB?

1。 Add-new filss-cocoa touch classes-object-c class

create a class UISpecialTableViewCell

2 that inherits from UITabelViewCell. Add-new files-user interface-empty XIB

create an empty UISpecialTableViewCell.xib file. Remember, the name of xib must be the same as the name of the signed class, that is, exactly the same.

you must choose the type of Empty XIB. If you don't choose this one, the existing UIView in the created XIB will not be able to adjust its height, and its height is fixed.

because it is an empty XIB file, all the controls drag a UIView into the file list box, and then change the class name of this UIView from UIView

to UISpecialTableViewCell in the property manager.

3。 In this way, we can add our own personalized controls to this newly added View, which is the template of our Cell. This process is the same as ordinary XIB, nothing special.

so how do you use this UISpecialTableViewCell in your code?

the code is as follows:

[CPP] view plain copy

-(uitableviewcell *) tableview: (uitableview *) tableview cell for rowatindexpath: (nsindexpath *). indexPath

static NSString *CellIdentifier = @"UISpecialTableViewCell";

UISpecialTableViewCell *cell = (UISpecialTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil)

{

cell= (UITwitterTableViewCell *)[[[NSBundle mainBundle] loadNibNamed:@"UISpecialTableViewCell" owner:self options:nil] lastObject];

}

// Some of your own settings

return (UITableViewCell *)cell;

}