2014-03-19 19 views
0
當新窗口/視圖

我的代碼現在爲didSelectItemAtIndexPath如下:編程示出了選擇UICollectionViewCell

- (void)collectionView:(AFIndexedCollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ 
if(collectionView.index == 0){ 
    NSLog(@"Reordenador contenido por columna %li",indexPath.item); 
    self.my_data = [self.my_data sortByColumn:indexPath.item skip:1 areAllNumbers:TRUE]; 
    [self.tableView reloadData]; 
}else{ 
//show a new window with the content of the cell in a Text Field 
    NSLog(@"Row = %li; Column = %li - content = %@",collectionView.index,indexPath.item,[self.my_data objectInRow:collectionView.index column:indexPath.item]); 
} 
} 

my_data =定製2D陣列類對象

如何將編程方式打開一個新的彈出窗口/包含所選單元格內容的新視圖,例如文本字段和2個按鈕 - 保存/取消?

回答

0

具有以下編碼修正:

UIView *mySubView = [[UIView alloc]initWithFrame:[[UIScreen mainScreen] bounds]]; 
    [mySubView setBackgroundColor:[UIColor blackColor]]; 
    mySubView.tag = TFIELDSUBVIEW_TAG; 
    self.textField = [[UITextField alloc] initWithFrame:CGRectMake(2, 10, 300, 80)]; 
    self.textField.borderStyle = UITextBorderStyleRoundedRect; 
    self.textField.font = [UIFont systemFontOfSize:12]; 
    self.textField.placeholder = [self.the_matrix objectInRow:collectionView.index column:indexPath.item]; 
    self.textField.autocorrectionType = UITextAutocorrectionTypeNo; 
    self.textField.keyboardType = UIKeyboardTypeDefault; 
    self.textField.returnKeyType = UIReturnKeyDone; 
    self.textField.clearButtonMode = UITextFieldViewModeWhileEditing; 
    self.textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; 
    self.textField.textAlignment = NSTextAlignmentCenter; 
    self.textFieldColumn = indexPath.item; 
    self.textFieldRow = collectionView.index; 
    UIButton *buttonOK = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    buttonOK.tag = TFIELDSUBVIEW_TAG; 
    [buttonOK setBackgroundImage:[UIImage imageNamed:@"ok.jpg"] forState:UIControlStateNormal]; 
    [buttonOK addTarget:self 
       action:@selector(okClicked) 
     forControlEvents:UIControlEventTouchUpInside]; 
    [buttonOK setTitle:@"" forState:UIControlStateNormal]; 
    buttonOK.backgroundColor = [UIColor grayColor]; 
    buttonOK.frame = CGRectMake(50, 100, 50, 30); 
    buttonOK.tintColor = [UIColor greenColor]; 
    UIButton *buttonCANCEL = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    buttonCANCEL.tag = TFIELDSUBVIEW_TAG; 
    [buttonCANCEL addTarget:self 
        action:@selector(cancelClicked) 
      forControlEvents:UIControlEventTouchUpInside]; 
    [buttonCANCEL setBackgroundImage:[UIImage imageNamed:@"cancel.jpg"] forState:UIControlStateNormal]; 
    [buttonCANCEL setTitle:@"" forState:UIControlStateNormal]; 
    buttonCANCEL.backgroundColor = [UIColor grayColor]; 
    buttonCANCEL.frame = CGRectMake(120, 100, 75, 30); 
    buttonCANCEL.tintColor = [UIColor redColor]; 
    [mySubView addSubview:buttonOK]; 
    [mySubView addSubview:buttonCANCEL]; 
    [mySubView addSubview:self.textField]; 

    [self setCustomView:mySubView]; 
    [self.view reloadInputViews]; 

setCustomView爲執行以下操作:

-(void) setCustomView:(UIView *)customView { 
    NSUInteger z = NSNotFound; 
    if (_customView) { 
     z = [self.view.subviews indexOfObject:_customView]; 
    } 
    if (z == NSNotFound) { 
     [self.view addSubview:customView]; 
    } else { 
     UIView *superview = _customView.superview; 
     [_customView removeFromSuperview]; 
     [superview insertSubview:customView atIndex:z]; 
    } 
    _customView = customView; 
} 
相關問題