IPhoneDevelopmentUITableViewThe code implementation example is described in this article.UITableViewThe basic operations are implemented by small instances. Let's look at the content.
1. Prerequisites
1.1UITableViewA UIView control must be loaded before you can add a UITableView.
1.2 The UITableView protocol <UITableViewDelegate, UITableViewDataSource>
The two protocols are as follows:
-- Number of rows:
- -(NSInteger) tableView :( UITableView *) table numberOfRowsInSection :( NSInteger) section
- {
- Return [tableArray count];
- }
-
- -- Define rows
-
- -(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath
- {
- Static NSString * SimpleTableIdentifier = @ "SimpleTableIdentifier ";
- UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:
- SimpleTableIdentifier];
- If (cell = nil)
- {
- // Default Style
- Cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault
- ReuseIdentifier: SimpleTableIdentifier] autoreler];
- }
- // Text settings
- NSUInteger row = [indexPath row];
- Cell. textLabel. text = [tableArray objectAtIndex: row];
- Return cell;
- }
2. Add UIView
- UIView * view = [[UIView alloc] initWithFrame: CGRectMake (0.0, 0.0, 320,260)];
- // Customize the recognition header and height
- View. autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHeight;
- View. backgroundColor = [UIColor blueColor];
- // Add the view to the main form
- [Self. view addSubview: view];
3. Add UITableView
- UITableView * table1 = [[UITableView alloc] initWithFrame: CGRectMake (0, 0.00, 300,250)];
- Table1.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHeight;
- Table1.backgroundColor = [UIColor redColor];
- // Add to view form
- [View addSubview: table1];
- Table1.delegate = self;
- Table1.dataSource = self;
4. Cancel click Animation
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
5. Scroll path identification until the specified position of the exponential continuous receiver on the screen
- - (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:
- (BOOL)animated Parameters
IndexPath
The index path identifies the index in its row, and some of its indicator table view rows.
ScrollPosition
A constant that ends when the relative position of the row, center, and bottom is scrolled.
Animated
If you want the animation to change its position, it should not take effect immediately.
Instance code:
- Float heights = 216.0;
- CGRect frame = m_pTableView.frame;
- Frame. size = CGSizeMake (frame. size. width, frame. size. height-height );
- [UIView beginAnimations: @ "Curl" context: nil]; // starts the animation.
- [UIView setAnimationDuration: 0.30];
- [UIView setAnimationDelegate: self];
- [M_pTableView setFrame: frame];
- [M_pTableView scrollToRowAtIndexPath: selectedIndexPath atScrollPosition: UITableViewScrollPositionMiddle animated: YES];
- [UIView commitAnimations];
6. Obtain the selected columns ,:
The Code is as follows:
- For (NSInteger I = 0; I <[peopleTableView visibleCells] count]; I ++)
- {
- UITableViewCell * cell = [[peopleTableView visibleCells] objectAtIndex: I];
- If (cell. accessoryType = UITableViewCellAccessoryCheckmark) // Add the selected personnel to the list.
- {
- Item * item = (Item *) [NextPeopleList. SelectList objectAtIndex: I];
- [PeopleList addObject: item];
- IsCheck = TRUE;
- }
- }
7. The Cell will display the current event
- - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if (indexPath.row % 2 == 0) {
- cell.backgroundColor = DarkColor;
- }else {
- cell.backgroundColor = LightColor;
- }
Summary:IPhoneDevelopmentUITableViewThe content of the code implementation instance has been introduced. I hope this article will help you!