2012-01-24 24 views
0

我擁有數組的項目,而數組包含字符串值和id.I想從數組中獲取id。我選擇任何行,然後id應該通過下一個視圖類來更新下一個視圖的數據。 我嘗試,但我不知如何傳遞ID的所有數據到下一個視圖改變如何從數組中提取id並將其傳遞給下一個視圖,其值爲iphone

- (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]; 
     //} 
    } 
} 

回答

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中之前被稱爲..

+0

您好,我想通過酥料餅通過我的ID不pushviewcontroller u能幫助我在此 – Rocky

+0

U可以做到pushVC只是一個例子.. – vishy

+0

但如何通過我的taskid從didselectrowatindexpath。我得到一個taskid從列表數組我的代碼是寫或錯誤odal * a =(模態*)[ listitems objectAtIndex:indexPath.row]; ([self.lstTasks objectAtIndex:indexPath.row] ==(NSInteger)a.Id) – Rocky

相關問題