IPhone application development UITableView

Source: Internet
Author: User

IPhoneApplication DevelopmentUITableViewI will introduce the content of this article with little content, mainly based on code implementation.UITableViewLet's look at the content.

-Create UITableView

 
 
  1. DataTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 420)];  
  2. [DataTable setDelegate:self];  
  3. [DataTable setDataSource:self];  
  4. [self.view addSubview:DataTable];  
  5. [DataTable release]; 

2. Description of UITableView Methods

 
 
  1. // Total number of sections
  2. -(NSArray *) sectionIndexTitlesForTableView :( UITableView *) tableView {
  3. Return TitleData;
  4. }
  5.  
  6. // Section Titles
  7. // The title displayed for each section
  8. -(NSString *) tableView :( UITableView *) tableView titleForHeaderInSection :( NSInteger) section {
  9. Return @"";
  10. }
  11.  
  12. // Specify the number of partitions. The default value is 1.
  13. -(NSInteger) numberOfSectionsInTableView :( UITableView *) tableView {
  14. Return 4;
  15. }
  16.  
  17. // Specify the number of rows in each partition. The default value is 1.
  18. -(NSInteger) tableView :( UITableView *) tableView numberOfRowsInSection :( NSInteger) section {
  19. }
  20.  
  21. // Draw a Cell
  22. -(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {
  23. Static NSString * SimpleTableIdentifier = @ "SimpleTableIdentifier ";
  24. UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:
  25. SimpleTableIdentifier];
  26. If (cell = nil ){
  27. Cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault
  28. ReuseIdentifier: SimpleTableIdentifier] autoreler];
  29. }
  30. Cell. imageView. image = image; // The image when no cell is selected
  31. Cell. imageView. highlightedImage = highlightImage; // The image after the cell is selected
  32. Cell. text = //.....
  33. Return cell;
  34. }
  35.  
  36. // Line indent
  37. -(NSInteger) tableView :( UITableView *) tableView indentationLevelForRowAtIndexPath :( NSIndexPath *) indexPath {
  38. NSUInteger row = [indexPath row];
  39. Return row;
  40. }
  41.  
  42. // Change the Row Height
  43. -(CGFloat) tableView :( UITableView *) tableView heightForRowAtIndexPath :( NSIndexPath *) indexPath {
  44. Return 40;
  45. }
  46.  
  47. // Locate
  48. [TopicsTable setContentOffset: CGPointMake (0, promiseNum * 44 + Chapter * 20)];
  49.  
  50. // Return the selected cell
  51. NSIndexPath * ip = [NSIndexPath indexPathForRow: row inSection: section];
  52. [TopicsTable selectRowAtIndexPath: ip animated: YES scrollPosition: UITableViewScrollPositionNone];
  53.  
  54. [TableView setSeparatorStyle: UITableViewCellSelectionStyleNone];
  55.  
  56. // Select the Cell to respond to the event
  57. -(Void) tableView :( UITableView *) tableView didSelectRowAtIndexPath :( NSIndexPath *) indexPath {
  58.  
  59. [TableView deselectRowAtIndexPath: indexPath animated: YES]; // The selected reversed color disappears immediately.
  60. }
  61.  
  62. // Determine the selected row to prevent the first row from being selected)
  63. -(NSIndexPath *) tableView :( UITableView *) tableView willSelectRowAtIndexPath :( NSIndexPath *) indexPath
  64. {
  65. NSUInteger row = [indexPath row];
  66. If (row = 0)
  67. Return nil;
  68. Return indexPath;
  69. }
  70.  
  71. // Indicates whether the del button is displayed on the cell.
  72. -(BOOL) tableView :( UITableView *) tableView canEditRowAtIndexPath :( NSIndexPath *) indexPath {
  73. }
  74.  
  75. // Edit the status
  76. -(Void) tableView :( UITableView *) tableView commitEditingStyle :( UITableViewCellEditingStyle) editingStyle
  77. ForRowAtIndexPath :( NSIndexPath *) indexPath
  78. {
  79. }
  80.  
  81. [TopicsTable setContentSize: CGSizeMake (0, controller. promiseNum * 44)];
  82. // Add an index table to the right
  83. -(NSArray *) sectionIndexTitlesForTableView :( UITableView *) tableView {
  84. }
  85.  
  86. // Return the Section title.
  87. -(NSString *) tableView :( UITableView *) tableView titleForHeaderInSection :( NSInteger) section {
  88. }
  89.  
  90. // Del button content during custom stroke
  91. -(NSString *) tableView :( UITableView *) tableView
  92. TitleForDeleteConfirmationButtonForRowAtIndexPath :( NSIndexPath *) indexPath
  93. // Jump to the specified row or section
  94. [TableView scrollToRowAtIndexPath: [NSIndexPath indexPathForRow: 0 inSection: 0] atScrollPosition: UITableViewScrollPositionBottom animated: NO];
  95.  
  96. 3. Create UILable multi-line display on UITableViewCell
  97.  
  98. -(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {
  99. Static NSString * CellIdentifier = @ "Cell ";
  100. UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];
  101. If (cell = nil ){
  102. Cell = [[[UITableViewCell alloc] initWithFrame: CGRectZero reuseIdentifier: CellIdentifier] autorelease];
  103. UILabel * Datalabel = [[UILabel alloc] initWithFrame: CGRectMake (10, 0,320, 44)];
  104. [Datalabel settag: 100];
  105. Datalabel. autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  106. [Cell. contentView addSubview: Datalabel];
  107. [Datalabel release];
  108. }
  109. UILabel * Datalabel = (UILabel *) [cell. contentView viewWithTag: 100];
  110. [Datalabel setFont: [UIFont boldSystemFontOfSize: 18];
  111. Datalabel. text = [data. DataArray objectAtIndex: indexPath. row];
  112. Cell. accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  113. Return cell;
  114. }
  115.  
  116. // Select the cell color
  117.  
  118. Typedef enum {
  119. UITableViewCellSelectionStyleNone,
  120. UITableViewCellSelectionStyleBlue,
  121. UITableViewCellSelectionStyleGray
  122. } UITableViewCellSelectionStyle
  123.  
  124. // Cell button format on the right
  125.  
  126. Typedef enum {
  127. UITableViewCellAccessoryNone, // don't show any accessory view
  128. UITableViewCellAccessoryDisclosureIndicator, // regular chevron. doesn't track
  129. UITableViewCellAccessoryDetailDisclosureButton, // blue button w/chevron. tracks
  130. UITableViewCellAccessoryCheckmark // checkmark. doesn' t track
  131. } UITableViewCellAccessoryType
  132. // Whether to add a line break
  133.  
  134. Typedef enum {
  135. UITableViewCellSeparatorStyleNone,
  136. UITableViewCellSeparatorStyleSingleLine
  137. } UITableViewCellSeparatorStyle // change the line feed color
  138.  
  139. TableView. separatorColor = [UIColor blueColor];

Summary:IPhoneApplication DevelopmentUITableViewI hope this article will help you!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.