- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell * cell;
cell = [tableView dequeueReusableCellWithIdentifier:@"Contact"];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Contact"];
}
NSString * grp = [groups objectAtIndex:indexPath.section];
NSArray * contactSection = [contactTitles objectForKey:grp];
cell.textLabel.text = [contactSection objectAtIndex:indexPath.row];
cell.imageView.image = [UIImage imageNamed:@"1.png"];
<span style="color:#FF6666;">cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;</span>
return cell;
}
<span style="color:#FF6666;">accessoryType的取值:
typedef NS_ENUM(NSInteger, UITableViewCellAccessoryType) {
UITableViewCellAccessoryNone, // don't show any accessory view
UITableViewCellAccessoryDisclosureIndicator, // regular chevron. doesn't track
UITableViewCellAccessoryDetailDisclosureButton, // blue button w/ chevron. tracks
UITableViewCellAccessoryCheckmark // checkmark. doesn't track
};
</span>
accessory button被按下后的响应函数为:
<pre name="code" class="objc">- <span style="color:#FF6666;">(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath</span>
{
UIAlertView * alert;
NSString *name = [NSString stringWithFormat:@"%@'s detail ",[contacts objectAtIndex:indexPath.row]];
alert = [[UIAlertView alloc]initWithTitle:@"detail" message:name delegate:self cancelButtonTitle:@"done" otherButtonTitles:nil];
[alert show];
}