About Swift TableView Linking

Asked 2 years ago, Updated 2 years ago, 85 views

Sorry for the basic question.
Why do I link data source and delete on storyboard when I use tableView on Swift?I've been looking at how to use tableView on various sites, but I don't know the difference because there are cases where it is linked or not.I would appreciate it if someone could tell me.Thank you for your cooperation.

swift tableview

2022-09-30 19:48

1 Answers

About datasource
You can view data in TableView.
Specifies the object responsible for returning the number of data to display, the number of sections, cell contents, etc.
Notifications are also invoked when changes are made to the data, such as deleting or inserting records.
Deleting or inserting records depends on whether the response method is implemented or not implemented.
TableView is a must.
If you do not specify anything, you should have a scroll view that only shows lines.
See the Apple formula here for more information.
https://developer.apple.com/documentation/uikit/uitableviewdatasource

understanding delete
When an event occurs on TableView, such as a cell selection event, the object specified in delete is called.
There are different methods called for each event, and events that are not implemented to be received are not notified when they occur.
You don't need to link TableView to display only and receive no events.
See the Apple formula here for more information.
https://developer.apple.com/documentation/uikit/uitableviewdelegate

About linking datasource and delete
In addition to using StoryBoard, data source and delete links can be written in code.
If it is not linked by StoryBoard, it may be linked by a code.
You should have registered objects in the datasource and delete properties of the TableView instance as follows:

self.tblView.datasource=self
self.tblView.delegate=self

That's all.
Please let me know if there are any mistakes.


2022-09-30 19:48

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.