Forum Archive

Please tell me about ‘tableview’ and ‘Navigation View’

tk_kenkyu

Nice to meet you.
I’m a beginner for using Python3.
(I’m a Japanese high school student, so if you aware of some grammatically mistakes, don’t mind.)

I’m developing a system, using UI on Pythonista3 for iOS.

I wish that the program works like this.

-procedure-
1.Start UI module
2.Select an item from the ‘tableview’ ‘s list.
3.Get the value of the selected item on procedure2.
4.Write the value acquired in procedure3 as character string in the specified text file and save it.

I wrote like ↓, but it didn’t work collectively.
Could you tell me what is different and how to rewrite it?

Then, I don’t understand how to use the ‘Navigation View’. (I searched on the Internet...) Can you tell me how to use or tell me the detailed website about this?

import ui
def tablewview1(sender):
    sel = sender.selected_row
    item= sender.items[sel]
    label.text = item
    f = open('test.txt', 'w', encoding= 'utf-8')
    f.write('label.item')
    f.close()

nav = ui.NavigationView(view)
tableview = nav['tableview1']
nav.present() 
JonB

If you search for pythonista navigationview, you will find some examples and tutorials.

https://forum.omz-software.com/topic/2604/navigationview-tutorials/2

NavigationView in pythonista is kind of tricky, because while you can push an pop views onto the stack, you cannot easily access those views. So, nav['tableview1'] doesnt work, instead you have to access from the actual view.

The tutorial above shows how to use a TableView with a NavigationView, so should help get you started. You will quickly find annoying things that you wish you had more control over, or additional navigatinview delegate methods.

enceladus

You can look at some examples of navigation view and tableview here.
https://github.com/encela95dus/ios_pythonista_examples

tk_kenkyu

Hi. Dear @JonB and @enceladus . I am grateful for your help. I looked at some examples of ‘navigation view’ and ‘tableview’ on GitHub.
I could understand how I can make and run the UI program with Navigation View, and I wrote some prototypes using templates.
However, I want to get the value of the selected item in the navigation view, but I failed to get it even though I searched how I can.
Here is a code which I wrote. When I made the program run, the console said ‘AttributeError: 'ShowTableView' object has no attribute 'selected_row'’.
I'm sorry for the second request but could you teach me how I can change it or show me the templates?

import console, os, ui
import ui
import os
class ShowTableView(object):
    def __init__(self):
        self.view = ui.load_view("ShowTableView")
        self.view.present("sheet")
        self.view.name = "Select"
        self.bt_empty_action(None)

        dir_items =(‘a’, ‘b’, ‘c’, ‘d’, ‘e’)
        tv1 = self.view["tableview1"]
        tv1.data_source = tv1.delegate = ui.ListDataSource(dir_items)
        tv1.data_source.delete_enabled = tv1.editing = False
        tv1.reload_data()

    def bt_dir_action(self, sender):
        sel = self.selected_row
        item = sender.items[sel]
        label.text = item.text 
   @ui.in_background
    def tv1_action(self, sender):
        info = sender.items[sender.selected_row]
        console.alert("info", "\n".join(["{} = {}".format(i, info[i]) for i in info]))


ShowTableView()
JonB

I believe you meant to use sender.selected_row instead of self.selected_row.

Note, if you are trying to have a one time prompt to have the user to select from a table, then take some one time action based on that, you might consider using the dialogs module. list_dialog wraps all of this logic, along with a modal wait that returns a value.

tk_kenkyu

i’m not your enemy.
i’m not your enemy.
i’m not your enemy.
i’m not your enemy.

I’m so sorry.
Thanks for answering my questions.
My mom scolded me for 2 months.
As far as I know my father is step father.
They always fight.
thank you