試圖確定爲什麼我不能讓我的新「藝術」菜單在didSelectRowAtIndexPath.
被選中後顯示我意識到它沒有被正確使用......另外,有沒有一種方法可以使它在兩次敲擊後顯示,還是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");
}
}
你嘗試調試?它是否在'didSelectRowAtIndexPath:'方法內? – 2013-05-01 01:56:05
如果didSelectRowAtIndexPath未觸發,則可能是您沒有正確設置TableView的委託。至於雙擊,您可能需要使用uigesturerecognizer來實現您自己的自定義操作方法來檢測水龍頭。 – ninehundredt 2013-05-01 01:58:05
你還有沒有[self.myTableView reloadData];在更新的didSelectRowAtIndexPath方法的末尾? – rdelmar 2013-05-01 02:16:36