表视图的列表按钮
SecondLevelViewController.h---查看前边例子
接口实现:
#import <Foundation/Foundation.h> #import "SecondLevelViewController.h" @interface RowControlsController : SecondLevelViewController { NSArray *list; } @property (nonatomic, retain) NSArray *list; - (IBAction)buttonTapped:(id)sender; @end | |
实现:
#import "RowControlsController.h" @implementation RowControlsController @synthesize list; //表视图按钮的点击事件 - (IBAction)buttonTapped:(id)sender { UIButton *senderButton = (UIButton *)sender; UITableViewCell *buttonCell = (UITableViewCell *)[senderButton superview]; //获取表视图的一行id NSUInteger buttonRow = [[self.tableView indexPathForCell:buttonCell] row]; //获取列表内容 NSString *buttonTitle = [list objectAtIndex:buttonRow]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"You tapped the button" message:[NSString stringWithFormat:@"You tapped the button for %@", buttonTitle] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; [alert release]; } - (void)viewDidLoad { NSArray *array = [[NSArray alloc] initWithObjects:@"R2-D2", @"C3PO", @"Tik-Tok", @"Robby", @"Rosie", @"Uniblab", @"Bender", @"Marvin", @"Lt. Commander Data", |