ios - 返回按钮到 tableView

标签 ios objective-c uitableview back-button

我有一个卡拉 OK 应用程序。第一个屏幕上是所有歌曲。有类别的菜单按钮。如果选择“古典音乐”按钮,则第一个屏幕的内容会发生变化。

当我选择一个单元格时,会出现一个带有后退按钮的新 View 。

我的问题是:当我按下后退按钮时,第一个屏幕上全是歌曲,即使之前只有经典音乐,我不想要这个。

这是返回 Action 的方法:

- (IBAction)back:(id)sender {
    ViewController *xyz=[[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"first"];
    [self presentViewController:xyz animated:YES completion:^(void)
     {

     }];
}

这是第一个 View 的实现:

-(void)viewDidLoad {

    categoryArray =[[NSMutableArray alloc]init];
    categoryArray = [allKeys valueForKey:@"category" ];



    feeds=[[NSMutableArray alloc]init];
    feeds=[allKeys valueForKey:@"feed_api"];

   if ([stories count] == 0) {
        for (int i=0; i<[feeds count]; i++) {
            NSString * path =[feeds objectAtIndex:i];
            [self parseXMLFileAtURL:path];

        }
       .............
    }
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    if (tableView.tag==0) {

    TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
    }
    // Set up the cell
    int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];

    cell.title.text=[[stories objectAtIndex: indexPath.row] objectForKey: @"title"];
   NSString * aux=[[stories objectAtIndex: indexPath.row] objectForKey: @"url"];
    NSString *   videoHTML =[NSString stringWithFormat: @"<iframe type=\"text/html\" width=\"100\" height=\"80\" src=\"%@\" frameborder=\"0\"></iframe>",aux] ;
    [cell.WEB loadHTMLString:videoHTML baseURL:nil];

    cell.title.numberOfLines=6;
    return cell;}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    if (!tableView.tag==0) {
        int row =indexPath.row;
        if (row==0) {
            self.title1.text=@"All Songs";
            [stories removeAllObjects];
            [self parse];
        }else
        {
        self.title1.text=[categoryArray objectAtIndex:indexPath.row-1];
        [stories removeAllObjects];
        NSString * path =[feeds objectAtIndex:indexPath.row-1];
        [self parseXMLFileAtURL:path];}
        i=0;
        [self showMenu:nil];//sender should be settingsButton;
    }

- (void)parseXMLFileAtURL:(NSString *)URL
{
    //stories = [[NSMutableArray alloc] init];

    //you must then convert the path to a proper NSURL or it won't work
    NSURL *xmlURL = [NSURL URLWithString:URL];

    // here, for some reason you have to use NSClassFromString when trying to alloc NSXMLParser, otherwise you will get an object not found error
    // this may be necessary only for the toolchain
    rssParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];

    // Set self as the delegate of the parser so that it will receive the parser delegate methods callbacks.
    [rssParser setDelegate:self];

    // Depending on the XML document you're parsing, you may want to enable these features of NSXMLParser.
    [rssParser setShouldProcessNamespaces:NO];
    [rssParser setShouldReportNamespacePrefixes:NO];
    [rssParser setShouldResolveExternalEntities:NO];

    [rssParser parse];

}

- (void)parserDidEndDocument:(NSXMLParser *)parser {

    NSLog(@"all done!");
    NSLog(@"stories array has %d items", [stories count]);
    if (self.tableView.tag==0) {
        [self.tableView reloadData];

    }
}

最佳答案

每次按回键时都会创建一个新的 View Controller ,您应该将 mainViewController 嵌入到导航 Controller 中。这样你就可以向前插入 View Controller 并向后弹出它们。

关于ios - 返回按钮到 tableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28518430/

相关文章:

ios - 有没有办法消除使用 [NSURLSessionConfiguration backgroundSessionConfiguration] 时的延迟?

objective-c - NSScanner - 性能缓慢 - (UITableView, NSXMLParser)

ios - 通过 iOS 应用程序发送 Facebook 消息(在后台)

ios - GradientLayer 不水平填充 UIButton 边界

ios - 这个方法的定义有什么问题? ( objective-C )

ios - 尽管设置了委托(delegate),但永远不会调用 heightForRowAtIndexPath

ios - 虽然我在 Storyboard上增加了 UITableViewCell 的高度,但在设备或模拟器上看不到

objective-c - 我的 UITableView 在每一行显示相同的项目

ios - 如何检查 iOS 设备上的互联网连接?

ios - FIRApp 配置失败 w/"Configure Durable Deep Link fails"