Когда я запускаю свое приложение, UITableViewCells пустые. Я пытаюсь заполнить их содержимым из «NSArray sortedArray», в котором перечислены даты в порядке убывания.UITableViewCells не будет заполняться из моего NSArray
Сортированный массив NSLog (@ "равен% @, а count -% lu, а строка с первым индексом -% @", sortedArray, (unsigned long) [sortedArray count], индексированный);
NSLog ВЫХОД:
2017-02-13 09: 50: 15,693 тест [22349: 7300081] сортируется массив ( "02/11/2017", "01/25/2017", «01/17/2017», «12/25/2016», «12/17/2016», «11/25/2016», «11/23/2016», «11/17/2016" , "10/11/2016", "10/06/2016", "08/08/2016", "08/05/2016", "08/01/2016", " 28.07.2016 ", «07/15/2016», «07/13/2016», «07/11/2016», «07/08/2016», «06/17/2016», «05/17/2016" , "02/18/2016", "01/18/2016", "12/18/2015", "11/18/2015", "10/18/2015", «09/18/2015», «08/18/2015», «07/18/2015»,«06/18/2015», «22.05.2012», «04/17/2015 », « 03/17/2015 », « 02/17/2015 », « 01/17/2015 » ), а счет 34, а строка с первым индексом i s 02/11/2017
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *strSessionID = [[NSUserDefaults standardUserDefaults]
stringForKey:@"sessionID"];
NSString *strURL = [NSString stringWithFormat:@"http://%@/get_statement_list?session_id=%@",
[[NSUserDefaults standardUserDefaults]stringForKey:@"serverName"], strSessionID];
NSURL *aURL = [NSURL URLWithString:strURL];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:aURL];
NSURLResponse *response = nil;
NSError *error = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error];
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil]; NSArray *jsonArray = [dict objectForKey:@"statements"];
NSMutableArray *pdfs = [[NSMutableArray alloc] init];
NSArray *sortedArray = [[NSArray alloc] init];
for (int i=0; i<[jsonArray count]; i++) {
NSDictionary* dates = [jsonArray objectAtIndex:i];
NSString *MM=[dates objectForKey:@"month"];
NSString *DD=[dates objectForKey:@"day"];
NSString *YY=[dates objectForKey:@"year"];
NSString *iDates = [NSString stringWithFormat: @"%@/%@/%@", MM, DD, YY];
[pdfs addObject:iDates];
}
//put in descending date order
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"MM/dd/yyyy"];
sortedArray = [pdfs sortedArrayUsingComparator:^NSComparisonResult(NSString
*obj1, NSString *obj2) {
NSDate *d1 = [df dateFromString: obj1];
NSDate *d2 = [df dateFromString: obj2];
return [d2 compare: d1];
}];
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:
(NSInteger)section
{
return [sortedArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:@"MyIdentifier"];
if (cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MyIdentifier"];
}
NSString *statements = [NSString stringWithFormat:@"%@",
[sortedArray objectAtIndex:indexPath.row]];
cell.textLabel.text = statements;
return cell;
}
Почему мои ячейки таблицы не заполняются объектами в sortedArray? Как это исправить?
PLS шоу полный код. Не показывать фрагменты кода. –
try '[tableview reloadData]' когда массив уже заполнен - может быть ваш массив заполнен до конца – Daivest