SplitViewController 的问题

发布于 2024-11-20 00:11:09 字数 2103 浏览 2 评论 0原文

我的 splitviewcontroller 有问题。 我有下面的代码,当我运行应用程序并按下 rootviewcontroller(这是一个表)时,下一个视图出现在 rootviewcontroller 部分,但不是详细视图。 我可以知道我哪部分代码做错了吗?

非常感谢

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }

    // Set up the cell
    Travel_Packer_HDAppDelegate *appDelegate = (Travel_Packer_HDAppDelegate *)[[UIApplication sharedApplication] delegate];
    Animal *animal = (Animal *)[appDelegate.animals objectAtIndex:indexPath.row];

    [cell setText:animal.name];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Navigation logic -- create and push a new view controller
    Travel_Packer_HDAppDelegate *appDelegate = (Travel_Packer_HDAppDelegate *)[[UIApplication sharedApplication] delegate];
    Animal *animal = (Animal *)[appDelegate.animals objectAtIndex:indexPath.row];

    if(self.animalView == nil) {
        DetailViewController *viewController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:nil];
        self.animalView = viewController;
        [viewController release];
    }

    // Setup the animation
    [self.navigationController pushViewController:self.animalView animated:YES];
    // Set the title of the view to the animal's name
    self.animalView.title = [animal name];
    // Set the description field to the animals description
    [self.animalView.animalDesciption setText:[animal description]];
    // Load the animals image into a NSData boject and then assign it to the UIImageView
    NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:[animal imageURL]]];
    UIImage *animalImage = [[UIImage alloc] initWithData:imageData cache:YES];
    self.animalView.animalImage.image = animalImage;

}

I have a problem with the splitviewcontroller.
I have the code below and when i run the app, and pressing the rootviewcontroller, which is a table, the next view appeared in the rootviewcontroller part but not the detailview.
May I know which part of code i did wrong?

Many Thanks

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }

    // Set up the cell
    Travel_Packer_HDAppDelegate *appDelegate = (Travel_Packer_HDAppDelegate *)[[UIApplication sharedApplication] delegate];
    Animal *animal = (Animal *)[appDelegate.animals objectAtIndex:indexPath.row];

    [cell setText:animal.name];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Navigation logic -- create and push a new view controller
    Travel_Packer_HDAppDelegate *appDelegate = (Travel_Packer_HDAppDelegate *)[[UIApplication sharedApplication] delegate];
    Animal *animal = (Animal *)[appDelegate.animals objectAtIndex:indexPath.row];

    if(self.animalView == nil) {
        DetailViewController *viewController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:nil];
        self.animalView = viewController;
        [viewController release];
    }

    // Setup the animation
    [self.navigationController pushViewController:self.animalView animated:YES];
    // Set the title of the view to the animal's name
    self.animalView.title = [animal name];
    // Set the description field to the animals description
    [self.animalView.animalDesciption setText:[animal description]];
    // Load the animals image into a NSData boject and then assign it to the UIImageView
    NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:[animal imageURL]]];
    UIImage *animalImage = [[UIImage alloc] initWithData:imageData cache:YES];
    self.animalView.animalImage.image = animalImage;

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

允世 2024-11-27 00:11:09

据我了解,分割视图控制器的每个窗格中都有导航控制器?
那么可能是下一行的问题:

[self.navigationController pushViewController:self.animalView animated:YES];

由于您刚刚将 AnimalView 推到左侧导航控制器,但您需要右侧(详细信息窗格)一个。

As I understood you have navigation controllers in each pane of split view controller?
Then probably the issue in next line:

[self.navigationController pushViewController:self.animalView animated:YES];

due to you've just pushed the animalView to left navigation controller but you need right (detail pane) one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文