Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.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
Ios 在DidselectRowAtIndexPath中应用条件_Ios_Uitableview - Fatal编程技术网

Ios 在DidselectRowAtIndexPath中应用条件

Ios 在DidselectRowAtIndexPath中应用条件,ios,uitableview,Ios,Uitableview,我有一个UITableView,其中包含不同类型的文件和文件夹,我设置了一个方法,一旦单击一行,该方法将传递给另一个视图控制器。我需要的是,一旦单击一行,它将检查该行中的文件类型,然后在此基础上连接到不同的UIViewController 我的UiTableView在每个单元格中有两个项目 单元格标签&单元格详细信息文本标签 DetailTextLabel保存主题类型 i、 e.文件夹(用于文件夹)和文件(用于jpeg、png等文件) 我想使用didselectrowatindexpath中的i

我有一个UITableView,其中包含不同类型的文件和文件夹,我设置了一个方法,一旦单击一行,该方法将传递给另一个视图控制器。我需要的是,一旦单击一行,它将检查该行中的文件类型,然后在此基础上连接到不同的UIViewController

我的UiTableView在每个单元格中有两个项目 单元格标签&单元格详细信息文本标签

DetailTextLabel保存主题类型 i、 e.文件夹(用于文件夹)和文件(用于jpeg、png等文件)


我想使用didselectrowatindexpath中的if条件来区分文件和文件夹

您可以通过检查
cell.detailTextLabel.text的值来做到这一点,如下所示:

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

    UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
    NSString *str = cell.detailTextLabel.text;

    if ([str isEqualToString:@"Folder"])
    {
        // Open Folder Detail View. For Example:
        FolderViewController* objVC = [[FolderViewController alloc] initWithNibName:@"FolderViewController" bundle:nil];
        [self.navigationController pushViewController:objVC animated:YES];
    }
    else if ([str isEqualToString:@"File"])
    {
        // Open File Detail View. For Example:
        FileViewController* objVC = [[FileViewController alloc] initWithNibName:@"FileViewController" bundle:nil];
        [self.navigationController pushViewController:objVC animated:YES];
    }
}
在.h文件中

    #import "FolderViewController.h"
    #import "FileViewController.h"

    @interface mainViewController : UIViewController {
            FolderViewController *folderViewObj;
            FileViewController *fileViewObj;
    }
在.m文件中

    - (void)viewDidLoad {
            [super viewDidLoad];

            folderViewObj = [[FolderViewController alloc] initWithNibName:@"FolderViewController" bundle:nil];
            fileViewObj = [[FileViewController alloc] initWithNibName:@"FileViewController" bundle:nil];
    }

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

            UITableViewCell * cell = [tblObj cellForRowAtIndexPath:indexPath];
            NSString *lblText = cell.DetailTextLabel.text;

            if ([lblText isEqualToString:@"Folder"])  {
                    [self.navigationController pushViewController:folderViewObj animated:YES];
            }
            else if ([lblText isEqualToString:@"File"])
            {
                    [self.navigationController pushViewController:fileViewObj animated:YES];
            }
    }

    -(void) dealloc {
            [folderViewObj release];
            [fileViewObj release];
            [super dealloc];
    }

使用这种方式,FolderViewController和FileViewController的对象只创建一次,而不是在用户可以选择uitableview的行时创建一次。

是的,如果您提到了条件,只需编写该条件,并使用
PerformsgueWithIdentifier
pushViewController
,等。根据条件(不同的文件类型)显示所需的
UIViewController
。您可以为CellForRowatineXpath方法添加一些代码吗?您是一个救生员…谢谢,仍然无法标记您的FolderViewController*objVC=[[FolderViewController alloc].每次按View时,它都会占用内存。它将如何自动释放?