2011-06-03 97 views
0

招呼每一个 我有表视图一个细胞,并且我在这个小区一个UITextView,用户可以编写自己想要的东西,这是cellForRow里面的代码:细胞与TextView的

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

回答

2

使用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 ; 


}