У меня возникла проблема с заполнением таблицы в следующем сегменте. В основном я отправляю все строки в одну комбинированную строку, а затем заполняю массив. Из этого массива я заполняю таблицу. Проблема в том, что это проявляется только в самой первой ячейке. Я бы хотел, чтобы каждая запись имела запятую для перехода к следующей ячейке. Вот код для первого ViewControler.hНаполнение таблицы из массива появляется только на первой ячейке
@interface ViewController : UIViewController {
IBOutlet UITableView *myTableView;
NSMutableArray *locationArray;
}
@property (nonatomic, retain) IBOutlet UITableView *myTableView;
@property (nonatomic, retain) NSMutableArray *locationArray;
- (void) populateLocationArray;
@end
Вот ViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSLog(@"Row Selected %i",indexPath.row);
if (indexPath.section==0) {
[self performSegueWithIdentifier:@"first" sender:nil];
}
}
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
NSLog(@"PrepareForSegueCalled");
LocationItems *destination = [segue destinationViewController];
//If statement for city pressed
destination.titleOfView = @"Boston";
NSArray *myStrings = [[NSArray alloc] initWithObjects:@"first", @"second", @"third", @"fourth", @"fifth", nil];
destination.arrayToBePopulatedString = [myStrings componentsJoinedByString:@" "];
// destination.arrayToBePopulatedString = [myStrings componentsJoinedByString:@"|"];
// [destination.populationArray addObjectsFromArray:myStrings];
}
Контроллер называется LocationItems это вид с таблицей, я хотел бы заполнить. Вот LocationItems.h
@interface LocationItems : UIViewController
{
IBOutlet UITableView *locationTableView;
NSString *titleOfView;
NSString *arrayToBePopulatedString;
NSMutableArray *populationArray;
NSMutableArray *bostonArray;
}
- (void) populateArray;
@property (nonatomic, retain) IBOutlet UITableView *locationTableView;
@property (strong, nonatomic) NSString *titleOfView;
@property (strong, nonatomic) NSString *arrayToBePopulatedString;
@property (strong, nonatomic) NSMutableArray *populationArray;
@property (nonatomic, retain) NSMutableArray *bostonArray;
@end
И, наконец, LocationItems.m
- (void)viewDidLoad
{
[super viewDidLoad];
bostonArray = [[NSMutableArray alloc] init];
[self populateArray];
//********************************************************
//If string = boston load some array containing the cities.
// Do any additional setup after loading the view from its nib.
}
- (void) populateArray {
[bostonArray addObject:arrayToBePopulatedString];
//[bostonArray addObject:populationArray];
//[bostonArray addObject:@"Boston"];
}
// 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];
[[cell textLabel] setNumberOfLines:1];
//[[cell textLabel] setLineBreakMode:
}
// Configure the cell.
[cell.textLabel setText:[bostonArray objectAtIndex:indexPath.row]];
return cell;
}
// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [bostonArray.self count];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSLog(@"Row Selected %i",indexPath.row);
}
Заранее прошу прощения за такой длинный вопрос, но считаю, что это необходимо, чтобы полностью объяснить мою проблему. Я просто хотел бы, чтобы каждая ячейка имела другое слово (первый, второй, третий, ect). Любая помощь будет принята с благодарностью.
Спасибо!
Как выглядит ваш массивToBePopulatedString? Использовать NSLog в ViewDidLoad в LocationItems.m – davis
Это используется в методе populateArray. [bostonArray addObject: arrayToBePopulatedString]; – Tanner