试图确定为什么我的新“艺术”菜单在被选中后无法显示,didSelectRowAtIndexPath.
我意识到它没有被正确使用......还有,有没有办法让我在点击两次后显示它,或者didSelectRowAtIndexPath
通过默认只工作一次?
-(void)viewDidAppear:(BOOL)animated
{
NSString *arts = @"Arts and Museums";
[arrayNo addObject:arts];
[[self myTableView] reloadData];
}
- (void)viewDidLoad
{
[super viewDidLoad];
arrayNo = [[NSMutableArray alloc] init];
[[self myTableView] setDelegate:self];
[[self myTableView] setDataSource:self];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [arrayNo count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell)
{
NSLog(@"CREATING NEW CELL");
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.textLabel.textColor = [UIColor whiteColor];
cell.textLabel.textAlignment = NSTextAlignmentCenter;
cell.textLabel.textColor = [UIColor colorWithRed:(100/255.0) green:(130/255.0) blue:(255/255.0) alpha:1.0];
}
cell.textLabel.text = [arrayNo objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if ([cell.textLabel.text isEqualToString: @"Arts and Museums"])
{
NSString *galleries = @"Art Galleries";
NSString *dramatic = @"Dramatic Arts";
NSString *museums = @"Museums";
[arrayNo addObject:galleries];
[arrayNo addObject:dramatic];
[arrayNo addObject:museums];
[self.myTableView reloadData];
}
}
** * ** * ** * ***更新** * ** * ** * ****
用下面的代码更新我之后didSelectRowAtIndexPath
,我看到它正在引用它,但是我的新菜单项没有弹出来替换旧数组。我尝试使用self.myTableView = nil
并重新加载数据,但它似乎没有效果?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if ([cell.textLabel.text isEqualToString: @"Arts and Museums"])
{
NSString *galleries = @"Art Galleries";
NSString *dramatic = @"Dramatic Arts";
NSString *museums = @"Museums";
[arrayNo addObject:galleries];
[arrayNo addObject:dramatic];
[arrayNo addObject:museums];
NSLog(@"LOADED");
}
}