2012-06-01 29 views
0

我有一个表格和1个部分和两行, 和向下我有一个按钮动作。如何在按钮动作中传递单元格选择值

在按钮操作中,我必须检查哪个单元格被点击,因为根据该单元格我必须打开电子邮件视图才能发送邮件。

我两个布尔值创建的,但它不能正常工作,还是我emailview得到没有细胞致电选择 这个代码我在做什么

@implementation View 
@synthesize Mytableview,selectedIndexPaths,value1,value2,cellselected; 
BOOL values[1]; 



// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [Mytableview dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    if ([indexPath row] == 0 && [indexPath section] == 0) 
    { 

     cell.textLabel.text= @"test"; 

     if (values[indexPath.row]) { 
      cell.accessoryType = UITableViewCellAccessoryCheckmark; 

     } else { 
      cell.accessoryType = UITableViewCellAccessoryNone; 
     } 
     value1=TRUE; 
    } 

    else if ([indexPath row] == 1 && [indexPath section] == 0) 
    { 
     cell.textLabel.text= @"test"; 
     value2=TRUE; 
    } 


     return cell; 
} 


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    //[Mytableview deselectRowAtIndexPath:indexPath animated:YES]; 
    //self.cellselected = indexPath.row; 

    UITableViewCell *cell = [Mytableview cellForRowAtIndexPath:indexPath]; 
    //here values is i give as array on top as BOOL values[1];i give size for it 
    values[indexPath.row] = !values[indexPath.row]; 

    if (values[indexPath.row]) { 
     cell.accessoryType = UITableViewCellAccessoryCheckmark; 
    } else { 
     cell.accessoryType = UITableViewCellAccessoryNone; 
    } 
} 


-(IBAction)ExportEmail 
{ 


    if (value1==FALSE) { 
     return; 
    } 
    else { 

    Class mailClass = (NSClassFromString(@"MFMailComposeViewController")); 
    if (mailClass != nil) 
{ 
// We must always check whether the current device is configured for sending emails 
     if ([mailClass canSendMail]) 
     { 
      [self displayComposerSheet]; 
     } 

    } 
    } 

} 
+0

当您检查FALSE时,将另一个BOOL值设置为FALSE当您将其中一个设置为TRUE时。就像你说'value1 = TRUE'的地方低于那个设置'value2 = FALSE'的地方。对于在该行下面的'value2 = TRUE'设置'value1 = FALSE'也是如此。 – iNoob

回答

0

声明类veriable NSIndexPath;

NSIndexPath *myIndexPath; 

修改您的didSelectRowAtIndexPath方法下面

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    UITableViewCell *cell = [Mytableview cellForRowAtIndexPath:indexPath]; 
    //here values is i give as array on top as BOOL values[1];i give size for it 

    myIndexPath = indexPath; 

    if (values[indexPath.row]) { 
     cell.accessoryType = UITableViewCellAccessoryCheckmark; 
    } else { 
     cell.accessoryType = UITableViewCellAccessoryNone; 
    } 
} 

您可以使用NSIndexPath在您按钮的IBAction为根据索引,你可以打开电子邮件。

-(IBAction)ExportEmail 
{ 
    if(myIndexPath.row==0){ 
    // send mail  
    }else if(myIndexPath.row==1){ 
    // send mail 
    } 
} 
+0

杰伊mehta我通过myindexpath按钮动作,但锄头知道哪个单元格被选中它仍然打开所有 – Rocky

+0

有更新我的答案 – jaym

+0

不,它不工作 – Rocky

相关问题