簡體   English   中英

UITableView didSelectRowAtIndex TabBar和子視圖不起作用

[英]UITableView didSelectRowAtIndex TabBar and Subview Not working

我在這個陷阱上扯了頭發,已經呆了幾個星期了。 XCode 4.2的構建針對IOS4,因此我正在處理.XIB文件。

我正在編寫一個iPhone應用程序,其中包含兩個通過tabBar提供的選項卡,1)我的藝術家,2)所有藝術家。 每個選項卡都有一個精美的UITableview。 還有一個詳細視圖,顯示有關該作品的更多信息。 (還有一個HUD顯示,它是Matej Bukovinski的MBProgressHUD的副本)

當我調用didSelectRowAtIndexPath時,我無法調出細節視圖來挽救生命。 (它確實可以正確觸發。

我知道我必須缺少一些基本知識,但是...我只是找不到它來挽救生命。

提前致謝。

-搶

AppDelegate.h

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate> {
    UINavigationController *navigationController;

}
@property (strong, nonatomic) UINavigationController *navigationController; 
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UITabBarController *tabBarController;
@end

AppDelegate.m

#import "AppDelegate.h"
#import "MyArtistsViewController.h"
#import "SecondViewController.h"
#import "TicketDetailView.h"
#import "viewTest.h"

@implementation AppDelegate

@synthesize window = _window;
@synthesize tabBarController = _tabBarController;
@synthesize navigationController =_navigationController; 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    //Test on navigationController
    //navigationController = [[UINavigationController alloc] initWithRootViewController:MyArtistsViewController];
    // Override point for customization after application launch.
    UIViewController *viewController1 = [[MyArtistsViewController alloc] initWithNibName:@"MyArtistsViewController" bundle:nil];
    //UINavigationController *viewController1 = [[MyArtistsViewController alloc] initWithNibName:@"MyArtistsViewController" bundle:nil];

    //UIViewController *tvc = [[TicketViewController alloc] initWithNibName:@"TicketViewController" bundle:nil]; 
    self.navigationController = [[UINavigationController alloc] initWithRootViewController:_tabBarController];


    UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];


    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}

MyArtistsViewController.h

#include "MBProgressHUD.h"
#import "TicketViewController.h"
@interface MyArtistsViewController : UIViewController
<MPMediaPickerControllerDelegate, UITableViewDelegate,CLLocationManagerDelegate,  
UITableViewDataSource, MBProgressHUDDelegate> 
{
    IBOutlet UITableView *tblEvents; 
    MBProgressHUD *HUD;

}
@property (nonatomic, retain) TicketViewController *detailViewController;
@property (nonatomic, retain) IBOutlet UITableView *tblEvents; 
@property (nonatomic, retain) IBOutlet CLLocationManager *locationManager; 
@property (nonatomic, retain) NSString *eventID, *artistName; 
@end

MyArtistsViewController.m

#import "MyArtistsViewController.h"
@synthesize ticketViewController; 
@synthesize detailViewController; 
@synthesize tblEvents;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = NSLocalizedString(@"Master", @"Master");
    }
    return self;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (!self.detailViewController) {
        self.detailViewController = [[TicketViewController alloc] initWithNibName:@"TicketViewController" bundle:nil];
    }
    [self.navigationController pushViewController:self.detailViewController animated:YES];
}
- (void)viewDidLoad
//Create the Spinner or (HUD, Heads Up Display)  to let the User know whats going on. 
    HUD = [[MBProgressHUD alloc] initWithView:self.view]; [self.view addSubview:HUD];
    [self.navigationController.view addSubview:HUD];

    HUD.delegate = self;
    HUD.labelText = @"Loading";
    HUD.detailsLabelText = @"Wow you read this far!";
    HUD.square = YES;
    [HUD show:YES]; 

    // Does a bunch of stuff

    [HUD show:NO];

在AppDelegate.m中,必須將UINavigationController添加到選項卡視圖控件而不是普通的View controller:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    //Test on navigationController
    //navigationController = [[UINavigationController alloc] initWithRootViewController:MyArtistsViewController];
    // Override point for customization after application launch.
    UIViewController *artistsVC = [[[MyArtistsViewController alloc] initWithNibName:@"MyArtistsViewController" bundle:nil] autorelease]; //remove autorelease if ARC support
    UINavigationController *viewController1 = [[[UINavigationController alloc] initWithRootViewController:artistsVC] autorelease];

    //UIViewController *tvc = [[TicketViewController alloc] initWithNibName:@"TicketViewController" bundle:nil]; 
    //self.navigationController = [[UINavigationController alloc] initWithRootViewController:_tabBarController];


    UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];


    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM