//指定有多少个分区(Section),默认为1
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
//指定每个分区中有多少行,默认为1
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
return [_recentCalls count];
}
//行缩进
-(NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath{
NSUInteger row = [indexPath row];
return row;
}
//改变行的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 50;
}
// Customize the appearance of table view cells
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//switch (indexPath.row) {
// case 0: {
// UITableViewCell *cellDefault = [tableView dequeueReusableCellWithIdentifier:@"cellDefault"];
// if (cellDefault == nil) {
// cellDefault = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellDefault"] autorelease];
// }
// cellDefault.textLabel.text = @"10086";
// return cellDefault;
// }
// break;
//
// case 1: {
// UITableViewCell*cellValue1 = [tableView dequeueReusableCellWithIdentifier:@"cellValue1"];
// if (cellValue1 == nil) {
// cellValue1 = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellValue1"] autorelease];
// }
// cellValue1.textLabel.text = @"10086";
// cellValue1.detailTextLabel.text = @"3:00 PM";
// return cellValue1;
// }
// break;
//
// case 2: {
// UITableViewCell*cellValue2 = [tableView dequeueReusableCellWithIdentifier:@"cellValue2"];
// if (cellValue2 == nil) {
// cellValue2 = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:@"cellValue2"] autorelease];
// }
// cellValue2.textLabel.text = @"10086";
// cellValue2.detailTextLabel.text = @"3:00 PM";
// return cellValue2;
// }
// break;
//
// case 3: {
// UITableViewCell *cellSubtitle = [tableView dequeueReusableCellWithIdentifier:@"cellSubtitle"];
// if (cellSubtitle == nil) {
// cellSubtitle = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cellSubtitle"] autorelease];
// }
// cellSubtitle.textLabel.text = @"10086";
// cellSubtitle.detailTextLabel.text = @"3:00 PM";
// return cellSubtitle;
// }
// break;
//
// case 4:{
// 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 = @"Text";
// cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
// return cell;
// }
// break;
//}
int index = indexPath.row;
static NSString *RecentCallIdentifier = @"RecentCall";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:RecentCallIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2
reuseIdentifier:RecentCallIdentifier] autorelease];
}
[self configCell:cell atIndexPath:indexPath];
// NSInteger row = [indexPath row];
// cell.textLabel.text = [self.recentCalls objectAtIndex:row];
// cell.textLabel.text = @"10086";
return cell;
}
// Configure the cell...
- (void)configCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
RecentCall *aCall = [_recentCalls objectAtIndex:indexPath.row];
cell.textLabel.text = aCall.displayName;
if (aCall.isMissed)
cell.textLabel.textColor = [UIColor redColor];
else
cell.textLabel.textColor = [UIColor blackColor];
if ([aCall.T_CallDate timeIntervalSinceNow] > -86400)
cell.detailTextLabel.text = [self.hourFormatter stringFromDate:aCall.T_CallDate];
else
cell.detailTextLabel.text = [self.dateFormatter stringFromDate:aCall.T_CallDate];
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
}
-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"willSelectRowAtIndexPath");
NSUInteger row = [indexPath row];
return indexPath;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
int index = [indexPath row];
NSLog(@"didSelectRowAtIndexPath %d",[indexPath row]);
}
-(void)tableView:( UITableView *) tableView accessoryButtonTappedForRowWithIndexPath:( NSIndexPath *)indexPath{
NSLog(@"accessoryButtonTappedForRowWithIndexPath %d",[indexPath row]);
int index = [indexPath row];
}