Вопрос

My code right now for didSelectItemAtIndexPath is the following:

- (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 = custom 2D array class object

How would I programmatically open a new popup window / new view with the content of the selected cell inside, for example, a Text Field, and 2 buttons - Save / Cancel?

Это было полезно?

Решение

Fixed with the following coding:

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 being the following:

-(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;
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top