я имею данные, как это:UITableView количество строки в разделе
(
{
code = 000932;
date = "2013-11-29 18:17:03";
},
{
code = 000933;
date = "2013-11-29 18:17:03";
},
{
code = 000934;
date = "2013-11-29 18:17:03";
},
{
code = 000935;
date = "2013-11-29 18:17:03";
},
{
code = 000936;
date = "2013-11-29 18:17:03";
},
{
code = 000937;
date = "2013-11-29 18:17:03";
},
{
code = 000938;
date = "2013-11-29 18:17:03";
},
{
code = 000939;
date = "2013-11-29 18:17:03";
},
{
code = 000940;
date = "2013-11-29 18:17:03";
},
{
code = 001004;
date = "2013-12-24 01:27:34";
},
{
code = 001005;
date = "2013-12-24 01:27:34";
},
{
code = 001006;
date = "2013-12-24 01:27:35";
},
{
code = 001007;
date = "2013-12-24 01:33:17";
},
{
code = 001008;
date = "2013-12-24 01:33:17";
},
{
code = 001009;
date = "2013-12-24 01:33:17";
}
)
то я отсортировать его и «ре-группу» его в NSMutableDictionary
:
-(void)fetchCoupon{
NSLog(@"3");
userCoupon *object;
//[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
NSString *url=[NSString stringWithFormat:@"%@/transaction/coupon/list",serverUrl];
NSDictionary *parameters = @{
@"token":[bbox_helper getToken],
};
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:url parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
BOOL found;
NSLog(@"data->%@",[responseObject objectForKey:@"data"]);
for(NSDictionary *news_objects in [responseObject objectForKey:@"data"]){
userCoupon *object=[[userCoupon alloc] initWithDictionary:news_objects];
if(![coupon containsObject:object]){
[coupon addObject:object];
}
}
for (object in coupon)
{
NSString *c = object.date;
found = NO;
for (NSString *str in [coupon_section allKeys])
{
if ([str isEqualToString:c])
{
found = YES;
}
}
if (!found)
{
[coupon_section setValue:[[NSMutableArray alloc] init] forKey:c];
}
}
// Loop again and sort the books into their respective keys
for (object in coupon)
{
[[coupon_section objectForKey:object.date] addObject:object];
}
NSLog(@"data---%@",[[coupon_section allKeys] sortedArrayUsingComparator:^(id a, id b) {
return [a compare:b options:NSNumericSearch];
}]);
NSLog(@"%lu",(unsigned long)[[[coupon_section allKeys] sortedArrayUsingComparator:^(id a, id b) {
return [a compare:b options:NSNumericSearch];
}]count]);
progressView.mode = MRProgressOverlayViewModeCheckmark;
progressView.titleLabelText = @"Done";
[table_transaction reloadData];
[table_gift reloadData];
[table_coupon reloadData];
[beetlebox performBlock:^{
[progressView dismiss:YES];
} afterDelay:2.0];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
progressView.mode = MRProgressOverlayViewModeCross;
progressView.titleLabelText = @"Failed communicating with server";
}];
}
затем в tableviewsection я создать как это
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return [[[[[coupon_section allKeys] sortedArrayUsingComparator:^(id a, id b) {
return [a compare:b options:NSNumericSearch];
}] reverseObjectEnumerator]allObjects] count];
}
}
, а затем в разделе titleheader
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)sections
{
return [[[[[coupon_section allKeys] sortedArrayUsingComparator:^(id a, id b) {
return [a compare:b options:NSNumericSearch];
}] reverseObjectEnumerator]allObjects]objectAtIndex:sections];;
}
}
, а затем количество подряд:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sections {
return [[[coupon_section allKeys] sortedArrayUsingComparator:^(id a, id b) {
return [a compare:b options:NSNumericSearch];
}]count];
}
///////////////////// клетки показывают
userCoupon *obj = [coupon objectAtIndex:indexPath.row];
static NSString* [email protected]"getGift";
pointCell *cell = [[pointCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cells];
if(!cell){
cell = [[pointCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cells];
}
NSLog(@"data->%@",obj.code);
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.merchant_name.text = obj.code;
cell.status.hidden = YES;
cell.icon_status.hidden = YES;
return cell;
результат is: https://i.cloudup.com/V3wW9w4glP.png
Я хочу, чтобы он был сгруппирован по дате (уже сделан), а затем получил право на данные в разделе с правильным значением. Кто-нибудь может мне с этим помочь??
Покажите свой 'cellForRowAtIndexPath:' и 'willDisplayCell' –
привет @ValentinShamardin уже добавил – YAZID
Как вы вилочный код для каждого раздела? Вы всегда используете 'indexPath.row' и не используете' indexPath.section'. В результате текст в каждом разделе один и тот же. –