UITablecell中的UITextView在自定义单元格上填充TextView文本

时间:2014-02-21 07:13:33

标签: ios uitableview custom-cell

我在我的应用程序中使用Custom UITableCell和动态UITextView。

我有一个关于ios7的问题,我解释如下:

我在UITable Cell Custom Button上创建了一个视图,如下所示。此视图包含UITextView以输入文本,稍后将其放在单元格上,如注释表。

    // For iOS7
        UITableView *table = nil;
        if([CommonFunction isiOS7]){
            table = (UITableView*)[[[[[sender superview] superview] superview] superview] superview];
            indexPath=[[NSIndexPath alloc] init];//
            indexPath = [table indexPathForCell:self];
        }
        else {
            indexPath=[[NSIndexPath alloc] init];//
            indexPath = [(UITableView *)self.superview indexPathForCell: self];
        }
        NSLog(@"indexPath:%@",indexPath);
        if (appDelegate.dictLogedInUserData) {
            //[(UITableView*)self.superview scrollToRowAtIndexPath:[(UITableView *)self.superview indexPathForCell:self] atScrollPosition:UITableViewScrollPositionTop animated:YES];
            [table scrollToRowAtIndexPath:[table indexPathForCell:self] atScrollPosition:UITableViewScrollPositionTop animated:YES];

            TextInputView *txtInput = [[TextInputView alloc] init];
            txtInput.delegate=self;

            if ([btnAddComment.titleLabel.text length]>0) {
                if (![btnAddComment.titleLabel.text isEqualToString:@"Add Comment"]) {
                    txtInput.txtComments.text = btnAddComment.titleLabel.text;
                }
            }
            txtInput.backgroundColor = [UIColor clearColor];
            //[(UITableView*)[self superview] setScrollEnabled:NO];
            [table setScrollEnabled:NO];
            [self addSubview:txtInput];
            [self bringSubviewToFront:txtInput];
}

当使用输入一些文本时我需要将这个UITextView文本值填入我的UITableCell CustomView,其代码如下,这是委托方法:

//InputText Delegates
- (void)didFinishInput:(NSString *)inputedText {
    btnAddComment.titleLabel.text = inputedText;


    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:indexPath, @"indexPath",
                          [NSString stringWithFormat:@"%@",inputedText],@"commentText",nil];
    NSLog(@"dict:%@",dict);
    topic *t = [appDelegate.arrayTopicsData objectAtIndex:indexPath.row];
    t.user_comment = inputedText;
    [appDelegate.arrayTopicsData replaceObjectAtIndex:indexPath.row withObject:t];

    [self LoadDataForIndex:indexPath];

    [delegate didAddComment:dict];

    [(UITableView*)[self superview] setScrollEnabled:YES];

    if ([inputedText length]<=0) {
        btnAddComment.titleLabel.text = @"Add Comment";
    }
}

在上面的代码中,当我在UITextView上输入文本并按下键盘的Done按钮时,它总是崩溃。它在iOS7中的indexPath上提供了EXE-BAD-Access。

当我将NSString传递给Method时,请帮助我如何在UITextView委托方法上获取Indexpath。

请帮帮我。

0 个答案:

没有答案
相关问题