【问题标题】:how to fetch id from array and pass this to next view with value according to id in iphone如何从数组中获取 id 并根据 iphone 中的 id 将其传递给下一个视图
【发布时间】:2012-01-24 06:25:43
【问题描述】:

我有一个项目数组,并且数组包含字符串值和 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];
        //}
    }   
}

【问题讨论】:

    标签: iphone objective-c


    【解决方案1】:

    在下一个类 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 之前调用。..

    【讨论】:

    • 嗨,我想通过弹出窗口而不是 pushviewcontroller 传递我的 id,你能帮我吗
    • 但是如何从 didselectrowatindexpath 传递我的任务 ID。我从列表数组中获取任务 ID 我在代码中所做的是写入或错误的 odal* a=(modal*)[listitems objectAtIndex:indexPath.row] ; if ([self.lstTasks objectAtIndex:indexPath.row]==(NSInteger) a.Id)
    • 你将该方法写入 EditTask 并修改此 EditTask* next = [[EditTask alloc] initWithId:object];
    • 我从数组 Tasksmodal* a=(Tasksmodal*)[self.lstTasks objectAtIndex:indexPath.row] 中获取 id 是正确的;或者我也尝试这样做但如果 ([self.lstTasks objectAtIndex :indexPath.row]==(NSInteger) taskobject.TaskId)请帮帮我
    • 在你的代码中还有 1 件事你有分配和初始化 popOver 两次,删除 1 个语句.. 输出你得到..?
    猜你喜欢
    • 1970-01-01
    • 2018-05-10
    • 1970-01-01
    • 2015-08-17
    • 1970-01-01
    • 2016-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多