通过电池阵列项目到另一个视图控制器 [英] Pass cell array item to another view controller

查看:83
本文介绍了通过电池阵列项目到另一个视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以这是我一直在阅读了一个共同的问题,我仍然在学习,所以请记住这一点。

基本上我的应用程序目前可让您添加项目到实现代码如下然后当你从表中选择一个单元格中查看它表明这是为了显示该单元格中的详细信息,另一种观点认为控制器。

在我的tableView实现文件的.m,我有code去点击一个单元格时,视图控制器:

   - (空)的tableView:(UITableView的*)的tableView didSelectRowAtIndexPath方法:(NSIndexPath *)indexPath {    SelectedItemViewController *选择查看= [[SelectedItemViewController页头] initWithNibName:@SelectedView捆绑:无];    [selectView.titleView的setText:@测试];    [个体经营performSegueWithIdentifier:@showSelected发件人:indexPath];
}

在'的setText'一块code的是我只是测试,看看我能够改变为textLabel在ViewCellController。

当用户保存一个新的项目,这是在以下赛格瑞code时,它返回到的TableView被调用。 内的TodoItem'是一个NSMutableArray。

   - (IBAction为)unwindToList:(UIStoryboardSegue *){赛格瑞
    AddToDoItemViewController *源= [Segue公司sourceViewController]
    内的TodoItem *项目= source.toDoItem;
    如果(项目!=无){
        [self.toDoItems ADDOBJECT:项目];
        [self.tableView reloadData];
    }
}

很显然,我做错了什么。

我想了解是如何,我可以:


  1. 选择一个单元格,从该指数在数组中因此不只是单元格数据,数据包括取数据:标题,描述,交货期和完成。


  2. 在另一个视图控制器显示它。


  3. 操作完成布尔值,并保存它,所以它仍然当再次点击的方式。


我不想要一个完整的答案只是要指出我在正确的方向,所以我可以工作了我自己,谢谢!


解决方案

  1. 在detailviewcontroller您可以设置内的TodoItem是一个弱的财产...

  2. 在mainviewcontroller的didselectrow实例您detailviewcontroller后,你可以再设置其内的TodoItem是来自您的mainviewcontroller的内的TodoItem在给定的索引路径

在detailviewcontroller你然后与从mainviewcontroller项工作以及

<醇开始=3>
  • 在开卷Segue公司,你必须是唯一的事情就是重新加载tableviews数据。

  • 希望你明白我的意思是:)

    So this is a common question which I have been reading up on, I am still learning so please keep that in mind.

    Basically my app currently lets you add an item to the tableview then when you select a cell from the table view it shows another view controller which is meant to display the detailed information for that cell.

    Diagram

    In my tableView implementation file .m, I have the code to go to the view controller when a cell is clicked:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
        SelectedItemViewController *selectView = [[SelectedItemViewController alloc] initWithNibName:@"SelectedView" bundle:nil];
    
        [selectView.titleView setText:@"test"];
    
        [self performSegueWithIdentifier:@"showSelected" sender:indexPath];
    }
    

    The 'setText' piece of code was me just testing to see if I was able to change the textLabel in the ViewCellController.

    When a user saves a new item, this is the following segue code that is called when it returns back to the TableView. 'toDoItem' is an NSMutableArray.

     -(IBAction)unwindToList:(UIStoryboardSegue *)segue {
        AddToDoItemViewController* source = [segue sourceViewController];
        ToDoItem* item = source.toDoItem;
        if (item != nil){
            [self.toDoItems addObject:item];
            [self.tableView reloadData];
        }
    }
    

    Obviously I am doing something wrong.

    What I am trying to understand is how I can:

    1. Select a cell, take the data from that index in the array so not just the cell data, data includes: Title, Description, DueDate and completion.

    2. Display it in another view controller.

    3. Manipulate the completion boolean value and save it so it remains that way when clicked again.

    I don't want a full answer just something to point me in the right direction so I can work it out on my own, Thanks!

    解决方案

    1. in your detailviewcontroller you could set toDoItem to be a weak property...
    2. in didselectrow of your mainviewcontroller after instantiating your detailviewcontroller you could then set its todoitem to be the todoitem from your mainviewcontroller at the given index path

    in your detailviewcontroller you are then working with the item from the mainviewcontroller and

    1. in your unwind segue the only thing you have to to is reload the tableviews data.

    hope you understand what i mean :)

    这篇关于通过电池阵列项目到另一个视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆