How to make an extensible TableView with Img profile?

I tried to create a menu with slides using SWRevealViewController , but I couldn't make an extensible TableView and profile with an image + Hi Name ...

what I need

And all I could do was:

what i have already done

Basically how do you create an extensible TableView and profile.

Are there any examples on how to do this?

+3


source to share


2 answers


From what I can tell you want an extensible table view , i.e .. Click a row in the table and more options will appear.

I have achieved this in the past using the following:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    if let cell = tableView.cellForRowAtIndexPath(indexPath) as? OuterCell{

        if let object = data[indexPath.row] as? OuterObject{
            if(object.open == false){
                data.insert(InnerObject(content: object.innerContent), atIndex: indexPath.row + 1)
                tableView.beginUpdates()
                tableView.insertRowsAtIndexPaths([NSIndexPath(forRow: indexPath.row + 1, inSection: 0)], withRowAnimation: .Left)
                tableView.endUpdates()
            }else{
                data.removeAtIndex(indexPath.row + 1)
                tableView.beginUpdates()
                tableView.deleteRowsAtIndexPaths([NSIndexPath(forRow: indexPath.row + 1, inSection: 0)], withRowAnimation: .Left)
                tableView.endUpdates()
            }
            object.open = !object.open
        }
    }
}

      

Basically what happens here is dataSource

for the TableView represented by the array data

in this example. This is what you connect to all tracks TableViewDelegate

.

I keep two types of objects in the data array: OuterObject and InnerObject.

The OuterObject contains all the information for the internal objects it contains, and if you click on it, it will dynamically add its children to the data array.

Sample data (I'm using JSON because it's easy to read and understand, you'll have to represent it quickly)



[
{
  name="Ensino",
  type="outerObject",
  open=true
  childObjects=[
    {
      name="Servico",
      type="innerObject"
    },
    {
      name="Avaliacao",
      type="innerObject"
    }
  ]
},
{
  name="Pesquisa",
  type="outerObject",
  open=false
  childObjects=[]
}
]

      

So, in your case, you need an Ensino object, with a child property containing data for: Avaliaco, Servicos, ect ...

The outer object also retains state as to whether it is open or closed or not, so if you click on it again, you can know to remove all inner objects belonging to it.

In this example I have hardcoded the OuterObject to always have at most one child, you will need to modify the code to be smarter about how many objects are inserted / removed after a click to be based on how many children the external object you are creating click.

Causing tableView.beginUpdates()

, tableView.beginUpdates()

, tableView.insertRowsAtIndexPaths()

, you get access to methods that will deliver an animated transition when updating data.

The key to solving this problem is to create a smart data source and then use the techniques that Apple has in UITableView

order to make this happen.

Let me know if you need more help, this is an advanced topic TableView

.

+5


source


check this sample code dropdown menu



this might give you some idea.

+1


source







All Articles