如何将详细视图控制器打开到新的视图控制器中?

时间:2014-07-22 09:31:44

标签: ios objective-c uitableview uisplitviewcontroller master-detail

我正在撰写一篇阅读iOS app的文章。在iPad中我使用的是分割视图控制器。
主视图控制器包含新闻,文章,媒体等菜单列表。 在详细视图控制器中单击菜单列表数据更新。详细视图控制器(UITableView)包含文章列表,当我单击文章时它在同一视图(详细信息视图控制器)中打开,我无法在新文章中打开该文章查看控制器。enter image description here

     - (void)viewDidLoad
       {
         [super viewDidLoad];
         NSLog(@"dshaghjdaS");
         UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20,10,0,20)];
         titleLabel.textColor = [UIColor blackColor];
          titleLabel.backgroundColor = [UIColor clearColor];
         titleLabel.text = @"Story";
        [self.navigationItem setTitleView:titleLabel];
           BOOL myBool = [self isNetworkAvailable];
          if (myBool)
           {
            @try {


              self.clearsSelectionOnViewWillAppear = NO;
               self.tableView.separatorColor = [UIColor colorWithRed:190/255.0 green:190/255.0   blue:190/255.0 alpha:1.0];
        // for displaying the previous screen lable with back button in details view controller
             UIBarButtonItem *backbutton1 = [[UIBarButtonItem alloc] initWithTitle:@""   style:UIBarButtonItemStyleBordered target:nil action:nil];

          [[self navigationItem] setBackBarButtonItem:backbutton1];


         _Title1 = [[NSMutableArray alloc] init];
         _Author1 = [[NSMutableArray alloc] init];
        _Images1 = [[NSMutableArray alloc] init];
        _Details1 = [[NSMutableArray alloc] init];
        _link1 = [[NSMutableArray alloc] init];
        _Date1 = [[NSMutableArray alloc] init];

        NSData* data = [NSData dataWithContentsOfURL:ysURL];
        NSLog(@"uuuuuuuuu%@",ysURL);
        NSArray *ys_avatars = [NSJSONSerialization JSONObjectWithData:data options:0  error:nil];

        if(ys_avatars){

            for (int j=0;j<ys_avatars.count;j++)
            {
                [_Title1 addObject:ys_avatars[j][@"title"]];
                [_Author1 addObject: ys_avatars[j][@"author"]];
                [_Images1 addObject: ys_avatars[j][@"featured_img"]];
                [_Details1 addObject:ys_avatars[j][@"content"]];
                [_link1 addObject:ys_avatars[j][@"permalink"]];
                NSString *newStr=[ys_avatars[j][@"date"] substringToIndex:[ys_avatars[j][@"date"] length]-3];
                [_Date1 addObject:newStr];
            }
        }
        else
        {
            NSLog(@"asd");

        }

    }
    @catch (NSException *exception) {

         UIAlertView *noConn = [[UIAlertView alloc] initWithTitle:@"ERROR" message:@"Please   Check Your Internet Connection" delegate:self cancelButtonTitle:nil otherButtonTitles:@"ok", nil];
        [noConn show];

    }


  }
   else
   {
      UIAlertView *noConn = [[UIAlertView alloc] initWithTitle:@"ERROR" message:@"Please Check  Your Internet Connection" delegate:self cancelButtonTitle:nil otherButtonTitles:@"ok", nil];
     [noConn show];

  }


} 




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

      static NSString *Cellidentifier1 = @"ysIpadDetailTableViewCell";
    ysIpadDetailTableViewCell *cell1 = [tableView   dequeueReusableCellWithIdentifier:Cellidentifier1 forIndexPath:indexPath];

// Configure the cell...

   long row = [indexPath row];
   cell1.TitleLabel1.text = _Title1[row];
   cell1.AuthorLabel1.text = _Author1[row];
   cell1.Ddate1.text = _Date1[row];



    NSString *newUrl = [_Images1[indexPath.row]      stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
   dispatch_queue_t taskQ = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_async(taskQ, ^{
    NSURL *Imageurl = [NSURL URLWithString:newUrl];
    NSData *data =  [NSData dataWithContentsOfURL:Imageurl];



    UIImage *images1 = [[UIImage alloc] initWithData:data];
    // Now the image will have been loaded and decoded and is ready to rock for the main thread
    dispatch_sync(dispatch_get_main_queue(), ^{
        ysIpadDetailTableViewCell *updateCell =(id)[tableView cellForRowAtIndexPath:indexPath];
        if(updateCell)
            updateCell.ThumbImage1.image=images1;
        cell1.ThumbImage1.image=images1;

        });


    });

    return cell1;

}

1 个答案:

答案 0 :(得分:0)

你需要实现UITableview Delegate方法。

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

    [self performSegueWithIdentifier:@"ShowDetails1" sender:self];
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if([[segue identifier] isEqualToString:@"ShowDetails1"])
    {
        // Your code goes here
    }
}

在设置UITableview委托之前。