0

I am working with Custom UITableCell and dynamic UITextView in my application.

I have one issue regarding ios7 which i explain as follows:

i have created one view on UITable Cell Custom Button click like as follows. this view contains UITextView to input the text and fell it on cell later as on comment table.

    // 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];
}

When use enter some text i need to fill this UITextView text value to my UITableCell CustomView which code is as follows,This is delegate method:

//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";
    }
}

In the above code it always crash when i enter text on UITextView and press Done button of key board. it gives EXE-BAD-Access on indexPath in iOS7.

Please help me how to get Indexpath on UITextView delegate method when i am passing NSString to the Method.

Please help me.

Hrushikesh Betai
  • 2,227
  • 5
  • 33
  • 63
  • Your indexPath seems released (the alloc/init is between two {}) when you try to get it. Put it as a strong property. – Larme Feb 21 '14 at 07:16
  • Still it crash on indexpath i have defined indexpath on header file as property (nonatomic,strong) – Hrushikesh Betai Feb 21 '14 at 07:25
  • I read again your code, you should delete the `[[NSIndexPath alloc]init];` line since you do after `indexPath =`. What says the `NSLog(@"indexPath:%@",indexPath);` you put? – Larme Feb 21 '14 at 07:31
  • In my first NSLog(@"indexPath:%@",indexPath); prints value but when i put another NSLog in - (void)didFinishInput:(NSString *)inputedText { it crashes application on that NSLog of indexPath. – Hrushikesh Betai Feb 21 '14 at 07:35

0 Answers0