Iphone 如何在按钮操作中传递单元格选择值
我有一个一节两行的tableview, 向下我有一个按钮动作 在按钮操作中,我必须检查单击了哪个单元格,因为根据该单元格,我必须打开电子邮件视图以发送邮件 我创建了两个bool值,但工作不正常,仍然选择了我的emailview get call With cell 这是我正在做的代码Iphone 如何在按钮操作中传递单元格选择值,iphone,objective-c,Iphone,Objective C,我有一个一节两行的tableview, 向下我有一个按钮动作 在按钮操作中,我必须检查单击了哪个单元格,因为根据该单元格,我必须打开电子邮件视图以发送邮件 我创建了两个bool值,但工作不正常,仍然选择了我的emailview get call With cell 这是我正在做的代码 @implementation View @synthesize Mytableview,selectedIndexPaths,value1,value2,cellselected; BOOL values[1];
@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];
}
}
}
}
声明类veriable nsindepath
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;
}
}
您可以在按钮的iAction中使用NSIndexPath,并根据索引打开电子邮件
-(IBAction)ExportEmail
{
if(myIndexPath.row==0){
// send mail
}else if(myIndexPath.row==1){
// send mail
}
}
在检查FALSE时,将另一个BOOL值设置为TRUE时,将另一个BOOL值指定为FALSE。就像你在该集合下方说的
value1=TRUE
一样value2=FALSE
。这一行下面的value2=TRUE
setvalue1=FALSE
也是如此。jay mehta我在按钮操作中传递myindexpath,但要知道选择了哪个单元格,它仍然会打开所有单元格,但会出现什么异常?你能粘贴你的错误或者进一步解释你的问题吗?这个代码不起作用,因为当你按下里面的按钮时,单元格没有被选中。你试过这个代码吗,我亲爱的朋友?myIndexPath是类级变量,一旦点击单元格,它将更改myIndexPath值。按下该按钮时无需选择单元格!你明白我的意思了吗!