xib
表格视图包含 7 行,我必须在其中选择 1 行,然后使用一些全局数据控制传输到另一个文件。
这怎么可能?
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
单击 tableview 中的某一行将调用此方法。
编辑:您可以在此方法中显示这样的警报
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Hello World!"
message:[NSString stringWithFormat:@"This is your UIAlertview message with row number %d.",indexPath.row]; delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[message show];
[message release];
}
NSMutableArray *mealArray = [[NSMutableArray alloc] init];
- (void)viewDidLoad
{
mealArray = [[NSMutableArray alloc]initWithObjects:@"Breakfast",@"Lunch",@"Dinner",@"Others", nil];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.textLabel.text = [mealArray objectAtIndex:indexPath.row];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
newViewController *newVC = [[newViewController alloc] init];
newVC.mealType = [mealArray objectAtIndex:indexPath.row];
[self.navigationController pushViewController:newVC animated:YES];
}