我使用tableView作为注册屏幕,并且我需要对每行强制执行一些长度限制。我使用了下面的函数,但它允许所有字段具有相同的约束。有人知道如何处理吗?
a = [[{'age_days': '72', 'age_years': '30', 'alpha_name': 'RAVAL,JA', 'batting_hand': 'left-hand batsman', 'batting_style': 'lhb', 'batting_style_long': 'left-hand bat', 'bowling_hand': 'right-arm bowler', 'bowling_pacespin': 'spin bowler', 'bowling_style': 'lb', 'bowling_style_long': 'legbreak ', 'captain': '0', 'card_long': 'JA Raval', 'card_qualifier': '', 'card_short': 'Raval', 'dob': '1988-09-22', 'keeper': '0', 'known_as': 'Jeet Raval', 'mobile_name': 'Raval', 'object_id': '277914', 'player_id': '51094', 'player_primary_role': 'opening batsman', 'player_style_id': '1', 'player_type': '1', 'player_type_name': 'player', 'popular_name': 'Raval', 'portrait_alt_id': '1', 'portrait_object_id': '397349', 'status_id': '3'}, {'age_days': '245', 'age_years': '26', 'alpha_name': 'LATHAM,TWM', 'batting_hand': 'left-hand batsman', 'batting_style': 'lhb', 'batting_style_long': 'left-hand bat', 'bowling_hand': 'right-arm bowler', 'bowling_pacespin': 'pace bowler', 'bowling_style': 'rm', 'bowling_style_long': 'right-arm medium ', 'captain': '0', 'card_long': 'TWM Latham', 'card_qualifier': '', 'card_short': 'Latham', 'dob': '1992-04-02', 'keeper': '0', 'known_as': 'Tom Latham', 'mobile_name': 'Latham', 'object_id': '388802', 'player_id': '59148', 'player_primary_role': 'wicketkeeper batsman', 'player_style_id': '7', 'player_type': '1', 'player_type_name': 'player', 'popular_name': 'Latham', 'portrait_alt_id': '1', 'portrait_object_id': '1099471', 'status_id': '3'}]]
b = [[{'age_days': '123', 'age_years': '25', 'alpha_name': 'LIVINGSTONE,LS', 'batting_hand': 'right-hand batsman', 'batting_style': 'rhb', 'batting_style_long': 'right-hand bat', 'bowling_hand': 'right-arm bowler', 'bowling_pacespin': 'spin bowler', 'bowling_style': 'lb', 'bowling_style_long': 'legbreak ', 'captain': '0', 'card_long': 'LS Livingstone', 'card_qualifier': '', 'card_short': 'Livingstone', 'dob': '1993-08-04', 'keeper': '0', 'known_as': 'Liam Livingstone', 'mobile_name': '', 'object_id': '403902', 'player_id': '59832', 'player_primary_role': None, 'player_style_id': None, 'player_type': '1', 'player_type_name': 'player', 'popular_name': '', 'portrait_alt_id': '1', 'portrait_object_id': '863825', 'status_id': '3'}, {'age_days': '142', 'age_years': '23', 'alpha_name': 'HAIN,SR', 'batting_hand': 'right-hand batsman', 'batting_style': 'rhb', 'batting_style_long': 'right-hand bat', 'bowling_hand': 'right-arm bowler', 'bowling_pacespin': 'spin bowler', 'bowling_style': 'ob', 'bowling_style_long': 'right-arm offbreak ', 'captain': '0', 'card_long': 'SR Hain', 'card_qualifier': '', 'card_short': 'Hain', 'dob': '1995-07-16', 'keeper': '0', 'known_as': 'Sam Hain', 'mobile_name': 'Hain', 'object_id': '555850', 'player_id': '67482', 'player_primary_role': None, 'player_style_id': None, 'player_type': '1', 'player_type_name': 'player', 'popular_name': 'Hain', 'portrait_alt_id': '1', 'portrait_object_id': '631902', 'status_id': '3'}]]
if len (a)==1 and len(b) ==1: # this checks if objects are single entity of players or multiple teams.
team_1 = pd.DataFrame.from_dict(a[0])
team_2 = pd.DataFrame.from_dict(b[0])
merged_team = pd.concat([df,df1], ignore_index=True)
merged_team
答案 0 :(得分:0)
由于您的文本字段委托方法位于单元格中,因此该单元格需要知道为其文本字段强制实施的长度。
您的视图控制器需要根据当前索引路径为cellForRowAt
中的每个单元格提供该长度。
向您的单元格类添加textLength
属性,然后根据需要在cellForRowAt
中设置该值。
然后,您在单元格类中的shouldChangeCharactersIn
可以使用该textLength
属性,而不是现在使用的硬编码12
。