yosifz8
yosifz8

Reputation: 561

cell with textView

hello every one i have table view with one cell,and i make on this cell a UITextView that the user can write what he want,this is the code inside the cellForRow:

static NSString *CellIdentifier = @"Cell";
UITextView *text;

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    text = [[UITextView alloc]initWithFrame:CGRectMake(1, 5, 200, 140)];
    text.tag = 1;

    UIView *statusView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 300, 150)];
    statusView.tag = 0;
    [statusView addSubview:text];
    [cell.contentView addSubview:statusView];
}
else {
    text = (UITextView *)[[cell.contentView viewWithTag:0] viewWithTag:1];
}

i want to make a save button and i want to know how i can take the text from this UITextView from another method in the class. thx

Upvotes: 0

Views: 413

Answers (1)

Jhaliya - Praveen Sharma
Jhaliya - Praveen Sharma

Reputation: 31722

Use UIButton to create the button and set a action (method) for that will be called when you click on button.

-(void) buttonPressed:(id) sender
{
   //First get the cell (We know we have the only one cell).

   // Create an NSIndexPath to access the cell from UITableView.
    NSIndexPath *myIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];

   //Now We can access the cell using UITableView instance.
   UITableViewCell *myCell = [myTabelView cellForRowAtIndexPath:myIndexPath];

   //Now access the instance of UITextView using viewWithTag property of UIView.
   UITextView* myTextView = (UITextView*) [myCell viewWithTag:1];


   //Now you could get the text. :)
   NSString* myTextViewText = myTextView.text ;


}

Upvotes: 2

Related Questions