我是新來的iOS,動態部分和行的UITableView
我開發UITableView
與動態行和部分
我想顯示在第一部分中的所有「今天」的數據,「明天」在其它區間和「星期日」的其他部分,等等...
碼我曾嘗試是,
這裏是我的數組:
{
"callbackSlotId": "1234-1234-3214-1233",
"callbackSlotName": "10:00-10:30",
"day": "today",
"availablenow": true
},
{
"callbackSlotId": "1234-1234-3214-1234",
"callbackSlotName": "11:00-11:30",
"day": "today",
"availablenow": false
},
{
"callbackSlotId": "1234-1234-3214-1235",
"callbackSlotName": "10:30-11:00",
"day": "today",
"availablenow": false
},
{
"callbackSlotId": "1234-1234-3214-1236",
"callbackSlotName": "10:30-11:00",
"day": "tomorrow",
"availablenow": false
},
{
"callbackSlotId": "1234-1234-3214-1237",
"callbackSlotName": "10:30-11:00",
"day": "tomorrow",
"availablenow": false
},
{
"callbackSlotId": "1234-1234-3214-1241",
"callbackSlotName": "10:30-11:00",
"day": "Sunday",
"availablenow": false
}
...
...
...
使用此代碼會顯示在多個部分中的所有數據:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [Array count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [Array count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellIdentifier"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellIdentifier"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
cell.textLabel.text=[Array objectAtIndex:indexPath.row];
return cell;
}
任何一個能幫助我嗎? 感謝閱讀
只需用'[elementsInSection addObject:arr]'替換'[elementsInSection addObject:day];'' –
感謝它的工作,但最後懷疑我怎麼在'cellForRowAtIndexPath'中顯示名爲'callbackSlotName'的valueForKey –
elementsInSection中的每個元素都是一個數組的NSDictionary,每個NSDictionary格式爲:「callbackSlotId」:「1234-1234-3214-1234」, 「callbackSlotName」:「11:00-11:30」, 「day」:「today」, 「所以你只需訪問 'NSDictionary * dict = [[elementsInSection objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];' – nynohu