-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbaseTableViewController.py
More file actions
167 lines (136 loc) · 5.21 KB
/
Copy pathbaseTableViewController.py
File metadata and controls
167 lines (136 loc) · 5.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import ctypes
from pyrubicon.objc.api import ObjCClass, ObjCInstance
from pyrubicon.objc.api import objc_method, objc_property
from pyrubicon.objc.api import NSString, NSMutableArray
from pyrubicon.objc.runtime import send_super, objc_id, send_message, SEL
from pyrubicon.objc.types import NSInteger
from rbedge.enumerations import UIListContentTextAlignment
from caseElement import CaseElement # todo: 型呼び出し
from rbedge.functions import NSStringFromClass
from rbedge import pdbr
UITableViewController = ObjCClass('UITableViewController')
UITableViewHeaderFooterView = ObjCClass('UITableViewHeaderFooterView')
UIListContentConfiguration = ObjCClass('UIListContentConfiguration')
class BaseTableViewController(UITableViewController):
testCells: NSMutableArray = objc_property()
headerFooterViewIdentifier: NSString = objc_property()
@objc_method
def dealloc(self) -> None:
# xxx: 呼ばない-> `send_super(__class__, self, 'dealloc')`
print(f'\t\t- {NSStringFromClass(__class__)}: dealloc')
@objc_method
def initWithStyle_(self, style: NSInteger) -> ObjCInstance:
send_super(__class__,
self,
'initWithStyle:',
style,
restype=objc_id,
argtypes=[
NSInteger,
])
#print(f'\t\t{NSStringFromClass(__class__)}: initWithStyle_')
return self
@objc_method
def loadView(self):
send_super(__class__, self, 'loadView')
#print(f'\t\t{NSStringFromClass(__class__)}: loadView')
self.testCells = NSMutableArray.new()
self.headerFooterViewIdentifier = 'customHeaderFooterView'
@objc_method
def viewDidLoad(self):
send_super(__class__, self, 'viewDidLoad') # xxx: 不要?
#print(f'\t\t{NSStringFromClass(__class__)}: viewDidLoad')
self.tableView.registerClass_forHeaderFooterViewReuseIdentifier_(
UITableViewHeaderFooterView, self.headerFooterViewIdentifier)
@objc_method
def viewWillAppear_(self, animated: bool):
send_super(__class__,
self,
'viewWillAppear:',
animated,
argtypes=[
ctypes.c_bool,
])
#print(f'\t{NSStringFromClass(__class__)}: viewWillAppear_')
@objc_method
def viewDidAppear_(self, animated: bool):
send_super(__class__,
self,
'viewDidAppear:',
animated,
argtypes=[
ctypes.c_bool,
])
#print(f'\t{NSStringFromClass(__class__)}: viewDidAppear_')
@objc_method
def viewWillDisappear_(self, animated: bool):
# print('\t↑ ---')
send_super(__class__,
self,
'viewWillDisappear:',
animated,
argtypes=[
ctypes.c_bool,
])
#print(f'\t{NSStringFromClass(__class__)}: viewWillDisappear_')
@objc_method
def viewDidDisappear_(self, animated: bool):
send_super(__class__,
self,
'viewDidDisappear:',
animated,
argtypes=[
ctypes.c_bool,
])
#print(f'\t{NSStringFromClass(__class__)}: viewDidDisappear_')
@objc_method
def didReceiveMemoryWarning(self):
send_super(__class__, self, 'didReceiveMemoryWarning')
print(f'\t{NSStringFromClass(__class__)}: didReceiveMemoryWarning')
@objc_method
def testCellsAppendContentsOf_(self, addingCells) -> None:
"""`@available(iOS 15.0, *)` で弾く用
"""
# wip
for cell in addingCells:
'''
if not isinstance(addCell, CaseElement):
continue
if (cell := addCell).configHandlerName is None:
continue
'''
self.testCells.addObject_(cell)
@objc_method
def centeredHeaderView_(self, title) -> objc_id:
headerView = self.tableView.dequeueReusableHeaderFooterViewWithIdentifier_(
self.headerFooterViewIdentifier)
content = UIListContentConfiguration.groupedHeaderConfiguration()
content.text = title
content.textProperties.alignment = UIListContentTextAlignment.center
headerView.contentConfiguration = content
return headerView
# MARK: - UITableViewDataSource
@objc_method
def tableView_viewForHeaderInSection_(self, tableView,
section: NSInteger) -> objc_id:
return self.centeredHeaderView_(self.testCells[section].title)
@objc_method
def tableView_titleForHeaderInSection_(self, tableView, section: NSInteger):
return self.testCells[section].title
@objc_method
def tableView_numberOfRowsInSection_(self, tableView,
section: NSInteger) -> NSInteger:
return 1
@objc_method
def numberOfSectionsInTableView_(self, tableView) -> NSInteger:
return len(self.testCells)
@objc_method
def tableView_cellForRowAtIndexPath_(self, tableView,
indexPath) -> ObjCInstance:
cellTest = self.testCells[indexPath.section]
cell = tableView.dequeueReusableCellWithIdentifier_forIndexPath_(
cellTest.cellID, indexPath)
if (view := cellTest.targetView(cell)):
configHandlerName = str(cellTest.configHandlerName)
self.performSelector_withObject_(SEL(configHandlerName), view)
return cell