首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在下一页从单元格tableView转到2页

如何在下一页从单元格tableView转到2页
EN

Stack Overflow用户
提问于 2013-04-16 09:55:14
回答 2查看 888关注 0票数 0

我创建了一个名为ViewControll的页面,即tableview。我从url中读取了2组NSString,并将其存储在NSMutableArray中。(名称:文件和文件夹)和这两个数组存储一个数组的名称:(全部)这个NSMutableArray显示在根页面(ViewController)

我有两页,另一页有名称:(TabelViewController & DetailViewController),TabelViewController用于文件夹数组,DetailViewController用于文件数组。

我希望何时单击单元格,如果该单元格来自文件夹数组,则继续到TableViewController页面,如果该单元格来自文件数组,则继续到DetailViewController页面。

这是我的代码,但不工作!:ViewController.h

代码语言:javascript
运行
复制
@interface ViewController : UITableViewController
{
    NSMutableArray *folder;
    NSMutableArray *file;
    NSMutableArray *all;
    NSInteger folderNumber,fileNumber;
}
@property (nonatomic,strong) IBOutlet UITableView *tables;
@end

ViewController.m

代码语言:javascript
运行
复制
@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSString *Number1 = [[NSString alloc]initWithContentsOfURL:[NSURL URLWithString:@"http://192.168.1.101/mamal/filemanager.php?dir=root&filenum"]];
     fileNumber = [Number1 integerValue];

    NSString *Number2 = [[NSString alloc]initWithContentsOfURL:[NSURL URLWithString:@"http://192.168.1.101/mamal/filemanager.php?dir=root&foldernum"]];
     folderNumber = [Number2 integerValue];

    NSLog(@"file: %d & folder: %d",fileNumber,folderNumber);

    for (int i=0; i < folderNumber; i++)
    {
        NSString *folderName = [[NSString alloc]initWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://192.168.1.101/mamal/filemanager.php?dir=root&folder=%d&name",i]]];
        if (!folder)
        {
            folder = [NSMutableArray array];
        }
        [folder addObject:folderName];
    }

    for (int j=0; j < fileNumber; j++)
    {
        NSString *fileName = [[NSString alloc]initWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://192.168.1.101/mamal/filemanager.php?dir=root&file=%d&name",j]]];
        NSLog(@"%@",fileName);
        if (!file)
        {
            file = [NSMutableArray array];
        }
        [file addObject:fileName];
    } 
    all = [[NSMutableArray alloc]init];
    [all addObjectsFromArray:folder];
    [all addObjectsFromArray:file];    
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return all.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"MyIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    cell.textLabel.text = [all objectAtIndex:indexPath.row];

    return cell;
}
#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"%d",indexPath.row+1);

    if (indexPath.row+1 <= folderNumber)
        {

            TableViewController *tab = [[TableViewController alloc]init];
            [self.navigationController pushViewController:tab animated:YES];
        }
    else
    {
        if (indexPath.row+1 > folderNumber)
        {
            DetailViewController *detail = [[DetailViewController alloc]init];
            [self.navigationController pushViewController:detail animated:YES];
        }
    }

}
EN

回答 2

Stack Overflow用户

发布于 2013-04-16 09:59:52

-initWithNibName:bundle:是UIViewController的指定初始化程序。

代码语言:javascript
运行
复制
TableViewController *vc = [[TableViewController alloc] initWithNibName:@"TableViewController" bundle:nil];

对视图控制器使用这种初始化。

票数 0
EN

Stack Overflow用户

发布于 2013-04-16 10:06:44

尝尝这个

在文件夹和文件的单个数组中搜索选定的名称

代码语言:javascript
运行
复制
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
  UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
  if([folder containsObject:[all objectAtIndex:indexPath.row])
    {
       TableViewController *tableVC = [storyboard instantiateViewControllerWithIdentifier:@"TableViewController"]; 
       [self.navigationController pushViewController:tableVC animated:YES]; 
    }
  else
    {
       DetailViewController *detail = [storyboard instantiateViewControllerWithIdentifier:@"DetailViewController"];
       [self.navigationController pushViewController:detail animated:YES]; 
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16033955

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档