开发者

Error with NSString

I have created a uitext view as below:

in the h.file
@property开发者_如何学Python (nonatomic, retain) NSString *strDescription;

in the m file

@synthesize strDescription;

- (void)viewDidLoad
{
   GRect frame = CGRectMake(0, 0, 320, 369);
    tblAddEquipment = [[UITableView alloc] initWithFrame:frame style:UITableViewStyleGrouped];
    tblAddEquipment.delegate = self;
    tblAddEquipment.dataSource = self;
    //avoid reusable
    [self.view addSubview:tblAddEquipment];
    self.tableView.scrollEnabled = YES;
    //self.tblAddEquipment.scrollEnabled = NO;
    [tblAddEquipment release];
    [self.tableView setSeparatorColor:[UIColor clearColor]];

}
- (void)textViewDidEndEditing:(UITextView *)textView
{
    strDescription = textView.text;
    NSLog(@"strDescription textView#####################--> %@", strDescription);
    [tblAddEquipment reloadData];
 }


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
      NSLog(@"str Description in tableview--> %@", strDescription);

      UITextView *txtDescription;

                   cellRectangle = CGRectMake( 175, 1, 120, 40 );               
                    txtDescription = [[UITextView alloc] initWithFrame: cellRectangle];
                    txtDescription.font = font;
                    //txtDescription.scrollEnabled = YES;
                    txtDescription.textColor = [UIColor blackColor];
                    txtDescription.autoresizingMask = UIViewAutoresizingFlexibleHeight;
                    [cell.contentView addSubview:txtDescription];   
                    txtDescription.returnKeyType = UIReturnKeyDone;
                    txtDescription.delegate = self;
                    txtDescription.tag = 10;
                    NSString *strDesc = strDescription;
                    NSLog(@"strDesc in tableview--> %@", strDesc);
                    txtDescription.text = strDesc;
                    [txtDescription release];


}

When I complete entering the text in the textview, textViewDidEndEditing method gets called.

In that, I get textView text input. I store it in the strDescription variable. I'm able to print it over there. It shows the text assigned to it correctly.

But when the cellForRowAtIndexPath method is called, I tried to print the strDescription variable, but it crashes and shows exc_bad_access.

I have been facing this issue for a long time. I don't know what I'm doing wrong here. Please help me up.


You have retained strDescription but in your code it seems me, you are not using that, because the below statement will not increment the retain count,

strDescription = textView.text;

Use below instead

self.strDescription = textView.text;

Use below code

- (void)textViewDidEndEditing:(UITextView *)textView
{
    self.strDescription = textView.text;
    NSLog(@"strDescription textView#####################--> %@", strDescription);
    [tblAddEquipment reloadData];
 }


First, this method

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

need to return UITableViewCell object i think…


Try changing the first line in textViewDidFinishEditing to this:

strDescription = [NSString stringWithFormatString:@"%@", textView.text]; 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜