Last time we implemented a basic interface for a music player, now we add songs and a list of channels to the player:
Implementing the list functionality is essentially configuring the UITableView control, which configures the UITableView to inherit the data source protocol and the two Protocol of the delegation Protocol:
Drag lines first to create TableView properties and inherit two protocols:
There are two methods in the data source protocol that must be implemented:
Then set the data source and proxy for the table:
Three simple steps, the song list is finished! ~
Next is the channel list.
The UI of the channel list is as follows, the configuration method is the same as above, it is worth mentioning that you can also directly bind the data source and the delegate with the Drag line method:
Create a new class as the controller for this view, with the following code:
Import UIKit
Class Channelcontroller:uiviewcontroller {
Channel TableView
@IBOutlet weak var tv:uitableview!
Override Func Viewdidload () {
Super.viewdidload ()
Do any additional setup after loading the view.
}
Override Func didreceivememorywarning () {
Super.didreceivememorywarning ()
Dispose of any resources the can be recreated.
}
Func TableView (Tableview:uitableview, Numberofrowsinsection section:int), int{
Return 8
}
Func TableView (Tableview:uitableview, Cellforrowatindexpath indexpath:nsindexpath), uitableviewcell{
Let cell = Tv.dequeuereusablecellwithidentifier ("channel") as! UITableViewCell
Cell.textlabel?. Text = "Channel: \ (Indexpath.row)"
return cell
}
}
Once completed, a simple channel list is implemented:
This basic UI is done, and the next time you'll be explaining how to get data from the web and present it in our app.
Song list and channel list