这是一个基本问题,我是swift的新手,这是关于Struct Arrays(struct inside struct)的具体问题
我正在尝试输出(带有标题作为节的TableView结构),如下所示:
我可以用词典做, 我正在尝试在struct
中创建数组的Structs:
struct StructSections {
var sectionName: String!
var channels: StructChannels
var collapsed: Bool!
init(sectionName: String, channels: StructChannels, collapsed: Bool = false) {
self.sectionName = sectionName
self.channels = channels
self.collapsed = collapsed
}
}
struct StructChannels{
var channelName: String!
var streamURL: String!
var imageURL: String!
}
然后我创建了加载数据的函数
func CreateRadioData() {
var JakartaChannels: [StructChannels] = []
JakartaChannels = [
StructChannels(channelName: "Prambors 102.2 FM Jakarta", streamURL: "http://masima.rastream.com/masima-pramborsjakarta", imageURL: "PramborsJakarta"),
StructChannels(channelName: "I-Radio 89.6 FM Jakarta", streamURL: "http://mra.rastream.com/mra_iradio", imageURL: "IRadioJakarta")
]
var MedanChannels: [StructChannels] = []
MedanChannels = [
StructChannels(channelName: "KISS 105 FM Medan", streamURL: "http://live.kissfm-medan.com:8080/kissfm.mp3", imageURL: "KissFMMedan")
]
var Sections:[StructSections] = []
Sections = [
StructSections(sectionName: "Jakarta", channels: JakartaChannels),
StructSections(sectionName: "Medan", channels: MedanChannels)
]
}
我在这些代码中遇到错误:
StructSections(sectionName: "Jakarta", channels: JakartaChannels),
StructSections(sectionName: "Medan", channels: MedanChannels)
如何在结构JakartaChannels
内调用结构MedanChannels
和StructSections
?
答案 0 :(得分:4)
在此语句中,您传递的是if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = NO;
picker.sourceType = sourceType;
picker.allowsEditing = YES;
[(UINavigationController *)[[self.window.subviews objectAtIndex:0] nextResponder] presentViewController:picker animated:YES completion:nil];
}
else{
//it is simulator or device with no camera source
// handle accordingly
}
数组,但只能StructChannels
参考。
StructChannels
所以,将StructSections(sectionName: "Jakarta", channels: JakartaChannels)
属性通道创建为StructSections
数组。
StructChannels
}