-、創建 UITableViewpromise
DataTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 420)]; [DataTable setDelegate:self]; [DataTable setDataSource:self]; [self.view addSubview:DataTable]; [DataTable release];
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{ return TitleData; }
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ return @""; }
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 4; }
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
}
-(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] autorelease]; } cell.imageView.image=image;//未選cell時的圖片 cell.imageView.highlightedImage=highlightImage;//選中cell後的圖片 cell.text=//..... return cell; }
-(NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath{ NSUInteger row = [indexPath row]; return row; }
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 40; }
[TopicsTable setContentOffset:CGPointMake(0, promiseNum * 44 + Chapter * 20)];
NSIndexPath *ip = [NSIndexPath indexPathForRow:row inSection:section];
[TopicsTable selectRowAtIndexPath:ip animated:YES scrollPosition:UITableViewScrollPositionNone];
[tableView setSeparatorStyle:UITableViewCellSelectionStyleNone];
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ [tableView deselectRowAtIndexPath:indexPath animated:YES];//選中後的反顯顏色即刻消失 }
-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSUInteger row = [indexPath row]; if (row == 0) return nil; return indexPath; }
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { } [topicsTable setContentSize:CGSizeMake(0,controller.promiseNum * 44)];
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
}
- (NSString *)tableView:(UITableView *)tableView
titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:NO];
1 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 2 static NSString *CellIdentifier = @"Cell"; 3 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 4 if (cell == nil) { 5 cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 6 UILabel *Datalabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 320, 44)]; 7 [Datalabel setTag:100]; 8 Datalabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 9 [cell.contentView addSubview:Datalabel]; 10 [Datalabel release]; 11 } 12 UILabel *Datalabel = (UILabel *)[cell.contentView viewWithTag:100]; 13 [Datalabel setFont:[UIFont boldSystemFontOfSize:18]]; 14 Datalabel.text = [data.DataArray objectAtIndex:indexPath.row]; 15 cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 16 return cell; 17 }
typedef enum { UITableViewCellSelectionStyleNone, UITableViewCellSelectionStyleBlue, UITableViewCellSelectionStyleGray } UITableViewCellSelectionStyle
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
typedef enum { UITableViewCellSeparatorStyleNone, UITableViewCellSeparatorStyleSingleLine } UITableViewCellSeparatorStyle//改變換行線顏色 tableView.separatorColor = [UIColor blueColor];