Как я могу сохранить NSMutableArray в таблицу, пока массив хранит другой массив различных объектов? - PullRequest
1 голос
/ 08 февраля 2011

У меня есть массив, я хочу сохранить его в UITable, но он не виден, мой код

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return [myArrayNew count];
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    // Configure the cell...
    NSString *cellValue = [myArrayNew objectAtIndex:indexPath.row];
    cell.textLabel.text = cellValue;
    return cell;
}

и этот массив имеет какой-то другой массив, а не отдельные объекты,

Ответы [ 3 ]

0 голосов
/ 08 февраля 2011

@ Veer использовать что-то вроде этого

NSArray *cellArray = [myArrayNew objectAtIndex:indexPath.row];
NSString *cellValue = [cellArray objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
return cell;

или что-то в этом роде. Если вы покажете нам, какой тип содержимого есть в myArrayNew, мы можем помочь вам больше.

РЕДАКТИРОВАТЬ: это просто пример, а не фактический ответ.

0 голосов
/ 08 февраля 2011

Вы должны сохранить значения в еще одном массиве ... и втором объекте массива, который вы можете назначить строке ..

0 голосов
/ 08 февраля 2011

Тогда вы должны кодировать по-другому,

[myArrayNew objectAtIndex:indexPath.row]; 

вернет массив объектов, а не строку.

EDIT:

Вы можете использовать секционное представление таблицы для отображения массива массива.

Так что код следующий,

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return [myArrayNew count];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return [[myArrayNew objectAtIndex:section]count];
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    // Configure the cell...
    NSString *cellValue = [[myArrayNew objectAtIndex:section]objectAtIndex:indexPath.row];
    cell.textLabel.text = cellValue;
    return cell;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...