返回按钮到tableView

时间:2015-02-14 17:51:29

标签: ios objective-c uitableview back-button

我有一个卡拉OK应用程序。在第一个屏幕上是所有的歌曲。有类别的菜单按钮。如果"经典音乐"选择按钮,第一个屏幕的内容被更改。

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

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

这是后退行动的方法:

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

     }];
}

这是第一个视图的实现:

-(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];

    }
}

1 个答案:

答案 0 :(得分:1)

每次回按时,你都会制作一个新的视图控制器,你应该将你的mainViewController嵌入到导航控制器中。这样你就可以继续推动视图控制器并向后弹出它们。