[Plain]
-Create UITableView
DataTable = [[UITableView alloc] initWithFrame: CGRectMake (0, 0,320,420)];
[DataTable setDelegate: self];
[DataTable setDataSource: self];
[Self. view addSubview: DataTable];
[DataTable release];
2. Description of UITableView Methods
// Total number of sections
-(NSArray *) sectionIndexTitlesForTableView :( UITableView *) tableView {
Return TitleData;
}
// Section Titles
// The title displayed for each section
-(NSString *) tableView :( UITableView *) tableView titleForHeaderInSection :( NSInteger) section {
Return @"";
}
// Specify the number of partitions. The default value is 1.
-(NSInteger) numberOfSectionsInTableView :( UITableView *) tableView {
Return 4;
}
// Specify the number of rows in each partition. The default value is 1.
-(NSInteger) tableView :( UITableView *) tableView numberOfRowsInSection :( NSInteger) section {
}
// Draw a Cell
-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {
Static NSString * SimpleTableIdentifier = @ "SimpleTableIdentifier ";
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:
SimpleTableIdentifier];
If (cell = nil ){
Cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault
ReuseIdentifier: SimpleTableIdentifier] autoreler];
}
Cell. imageView. image = image; // The image when no cell is selected
Cell. imageView. highlightedImage = highlightImage; // The image after the cell is selected
Cell. text = //.....
Return cell;
}
// Line indent
-(NSInteger) tableView :( UITableView *) tableView indentationLevelForRowAtIndexPath :( NSIndexPath *) indexPath {
NSUInteger row = [indexPath row];
Return row;
}
// Change the Row Height
-(CGFloat) tableView :( UITableView *) tableView heightForRowAtIndexPath :( NSIndexPath *) indexPath {
Return 40;
}
// Locate
[TopicsTable setContentOffset: CGPointMake (0, promiseNum * 44 + Chapter * 20)];
// Return the selected cell
NSIndexPath * ip = [NSIndexPath indexPathForRow: row inSection: section];
[TopicsTable selectRowAtIndexPath: ip animated: YES scrollPosition: UITableViewScrollPositionNone];
[TableView setSeparatorStyle: UITableViewCellSelectionStyleNone];
// Select the Cell to respond to the event
-(Void) tableView :( UITableView *) tableView didSelectRowAtIndexPath :( NSIndexPath *) indexPath {
[TableView deselectRowAtIndexPath: indexPath animated: YES]; // The selected reversed color disappears immediately.
}
// Determine the selected row (to prevent the first row from being selected)
-(NSIndexPath *) tableView :( UITableView *) tableView willSelectRowAtIndexPath :( NSIndexPath *) indexPath
{
NSUInteger row = [indexPath row];
If (row = 0)
Return nil;
Return indexPath;
}
// Indicates whether the del button is displayed on the cell.
-(BOOL) tableView :( UITableView *) tableView canEditRowAtIndexPath :( NSIndexPath *) indexPath {
}
// Edit the status
-(Void) tableView :( UITableView *) tableView commitEditingStyle :( UITableViewCellEditingStyle) editingStyle
ForRowAtIndexPath :( NSIndexPath *) indexPath
{
}
[TopicsTable setContentSize: CGSizeMake (0, controller. promiseNum * 44)];
// Add an index table to the right
-(NSArray *) sectionIndexTitlesForTableView :( UITableView *) tableView {
}
// Return the Section title.
-(NSString *) tableView :( UITableView *) tableView titleForHeaderInSection :( NSInteger) section {
}
// Del button content during custom stroke
-(NSString *) tableView :( UITableView *) tableView
TitleForDeleteConfirmationButtonForRowAtIndexPath :( NSIndexPath *) indexPath
// Jump to the specified row or section
[TableView scrollToRowAtIndexPath: [NSIndexPath indexPathForRow: 0 inSection: 0] atScrollPosition: UITableViewScrollPositionBottom animated: NO];
3. Create UILable multi-line display on UITableViewCell
-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {
Static NSString * CellIdentifier = @ "Cell ";
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];
If (cell = nil ){
Cell = [[[UITableViewCell alloc] initWithFrame: CGRectZero reuseIdentifier: CellIdentifier] autorelease];
UILabel * Datalabel = [[UILabel alloc] initWithFrame: CGRectMake (10, 0,320, 44)];
[Datalabel settag: 100];
Datalabel. autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[Cell. contentView addSubview: Datalabel];
[Datalabel release];
}
UILabel * Datalabel = (UILabel *) [cell. contentView viewWithTag: 100];
[Datalabel setFont: [UIFont boldSystemFontOfSize: 18];
Datalabel. text = [data. DataArray objectAtIndex: indexPath. row];
Cell. accessoryType = UITableViewCellAccessoryDisclosureIndicator;
Return cell;
}
// Select the cell color
Typedef enum {
UITableViewCellSelectionStyleNone,
UITableViewCellSelectionStyleBlue,
UITableViewCellSelectionStyleGray
} UITableViewCellSelectionStyle
// Cell button format on the right
Typedef enum {
UITableViewCellAccessoryNone, // don't show any accessory view
UITableViewCellAccessoryDisclosureIndicator, // regular chevron. doesn't track
UITableViewCellAccessoryDetailDisclosureButton, // blue button w/chevron. tracks
UITableViewCellAccessoryCheckmark // checkmark. doesn' t track
} UITableViewCellAccessoryType
// Whether to add a line break
Typedef enum {
UITableViewCellSeparatorStyleNone,
UITableViewCellSeparatorStyleSingleLine
} UITableViewCellSeparatorStyle
// Change the line feed color
TableView. separatorColor = [UIColor blueColor];
Author: js_dada