如何从数组中获取id并根据iphone中的id将其传递给下一个视图

时间:2012-01-24 06:25:44

标签: iphone objective-c

我有项数组,数组包含字符串值和id。我想在表视图行选择中从数组中获取id。如果我选​​择任何行,则id应该传递下一个视图类以更新下一个视图的数据。  我尝试但我混淆了如何将id与所有数据传递到下一个视图以进行更改

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [MyTableview deselectRowAtIndexPath:indexPath animated:YES];
    if (self.editing) {
        //Here
       //modal is my class where i create all string variable and id variable to get database value
       // here i want to pass id with next view please help here how to pass id at indexpath.row
        modal* a=(modal*)[listitems objectAtIndex:indexPath.row];

        if ([self.lstTasks objectAtIndex:indexPath.row]==(NSInteger) a.Id)

        EditTask* content = [[EditTask alloc] initWithNibName:@"EditTask" bundle:nil];
        content.navigationItem.title = @"Edit Task";
        navController = [[UINavigationController alloc] initWithRootViewController: content]; 
        _popover = [[UIPopoverController alloc] 
                    initWithContentViewController:navController];
         [content release];
        [navController release];

        _popover = [[UIPopoverController alloc] 
                    initWithContentViewController:navController];
        _popover.popoverContentSize = CGSizeMake(350, 450);
        UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        [_popover presentPopoverFromRect:cell.bounds inView:cell.contentView 
                permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
        //}
    }   
}

1 个答案:

答案 0 :(得分:0)

在下一个类viewController中实现以下内容

in interface
ObjectClass* object;

- (id)initWithId:(id)object;

在实施中

- (id) initWithId:(id)object
{
     self = [super init];
     if (self)
      {
          object = [object retain];
      }
}

和didSelect方法

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
   // get the object
   nextVC* next = [[nextVC alloc] initWithId:object];
   [self.navigationController pushViewController:next animated:YES];
   [next release];
 }

这样你可以将任何对象传递给你的下一个视图,这将在下一个类的viewDidLoad之前调用..