我是新来的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