Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 具有文本视图的单元格_Iphone_Objective C - Fatal编程技术网

Iphone 具有文本视图的单元格

Iphone 具有文本视图的单元格,iphone,objective-c,Iphone,Objective C,大家好 我有一个单元格的表视图,我在这个单元格上创建了一个UITextView,用户可以编写他想要的内容,这是cellForRow中的代码: static NSString *CellIdentifier = @"Cell"; UITextView *text; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [

大家好 我有一个单元格的表视图,我在这个单元格上创建了一个UITextView,用户可以编写他想要的内容,这是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];
}
我想制作一个保存按钮,我想知道如何从类中的另一个方法获取这个UITextView中的文本。
thx

使用
UIButton
创建按钮,并设置一个操作,该操作将在您单击按钮时调用

-(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 ;


}