我在下一个segue中填充tableview时出现问题。基本上我将所有字符串发送到一个组合字符串中,然后用它填充一个数组。从该阵列我填充表。问题是这只出现在第一个单元格中。我想为每个有逗号的条目打开下一个单元格。这是第一个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
最后
- (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);
}
我提前道歉了这么长的问题,但认为有必要充分说明我的问题LocationItems.m。我只想让每个单元格有不同的词(第一,第二,第三等)。任何帮助将不胜感激。
谢谢!
你的arrayToBePopulatedString看起来像什么?在LocationItems.m中使用ViewDidLoad中的NSLog – davis
在populateArray方法下使用。 [bostonArray addObject:arrayToBePopulatedString]; – Tanner