0

i am trying to add uitextview as subview of uitabaleview's cell and for that i am creating uitextview programatically in cellForRowAtIndex and i want it to be display the text dynamically from the nsmutablearray to uitextview however problem is ... how to differentiate for different uitextview of particular uitableview's cell. my code is in this way.......

- (UITableViewCell *)tableView:(UITableView *)tv
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *CellIdentifier=@"cell";
    UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil)

 {

        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }

    @try{

    // Set up the cell...

    if (tv == self.smsTableView) {

        int count1=[smsTxt count];

        int rowCount=indexPath.row;

    int index1=(count1-(rowCount+1));

        NSLog(@"count:::%d",count1);

        NSLog(@"row count:::%d",rowCount);

        NSString *cellValueSMSTxt = [self.smsTxt objectAtIndex:index1];

        UITextView *msgView=[[UITextView alloc]init];

        msgView.frame=CGRectMake(12, 15, 280, 45);
        msgView.font=[UIFont systemFontOfSize:12.0];
        msgView.editable=FALSE;
        msgView.textColor=[UIColor grayColor];
        msgView.backgroundColor=[UIColor clearColor];
        msgView.text=cellValueSMSTxt;
        arrMsgView=[[NSMutableArray alloc]init];
        [arrMsgView addObject:msgView];
        [msgView release];
        UITextView *tempTextView=[arrMsgView objectAtIndex:rowCount];
        NSLog(@"countforarr:::%d",[arrMsgView count]);
        [cell.contentView addSubview:tempTextView];
        [arrMsgView release];

    }
    }@catch (NSException *e) {
        NSLog(@"%@",e);


    }
2
  • the content of UITextView is not ready when cellForRowAtIndexPath: is called ? Commented Dec 6, 2011 at 8:59
  • no when i am not using nsmutablearray then it shows output but text of uitextview is overlaped so i want to add this uitextview;s object in nsmutable array for every new text Commented Dec 6, 2011 at 9:17

1 Answer 1

1

You can differentiate by subclassing UITableViewCell and keeping pointers to the different UITextView, or by setting a tag on the UITextView (tag is a UIView property):

@property(nonatomic) NSInteger tag

As it is now you are creating an array to hold the UITextViews and destroying it, which doesn't get you very far.

 arrMsgView=[[NSMutableArray alloc]init];
 [arrMsgView addObject:msgView];
 [msgView release];
 UITextView *tempTextView=[arrMsgView objectAtIndex:rowCount];
 NSLog(@"countforarr:::%d",[arrMsgView count]);
 [cell.contentView addSubview:tempTextView];
 [arrMsgView release];

What you could do to access a given UITextView is loop through the contentView subviews looking for a given object:

for (UIView* v in [contentView subviews]) {
    if ([v isKindOfClass:[UITextView class]] && v.tag == someIdTag) {
        // do something
    }
}

in which case you wouldn't need an additional array at all (the subviews object is an array).

Sign up to request clarification or add additional context in comments.

2 Comments

when i quit and again run the application every thing is fine however when i update or add soe text to uitextview of uitableviewcell then the text get overlaped...why this is hapening
you should ask another question, explaining your problem clearly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.