-5

xib表格视图包含 7 行,我必须在其中选择 1 行,然后使用一些全局数据控制传输到另一个文件。

这怎么可能?

4

3 回答 3

3
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
于 2013-02-23T09:43:33.403 回答
2
- (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];
}
于 2013-02-23T09:43:24.600 回答
1
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];
 }
于 2013-02-23T10:13:09.490 回答