xcodeの初心者なので、ここで学んでいます。これについては完全に間違っているかもしれませんが、これが私のシナリオです。ナビゲーションコントローラーに移動するボタンを備えたオープニングビューコントローラーのストーリーボードがあります。これにより、テーブルビューを使用してmysqlデータベースからエンターテイメントのリストがロードされます(これは正常に機能しています)。詳細ビューですが、何も起こっていません。デバッガーにエラーはありません。私は何を間違っていますか、またはこれについて間違った方法で行っていますか。問題は、didSelectRowAtIndexPath が行われている ENTERTAILMENTLISTING.M のセクションに関係していると思います。これまでのすべてを以下に含めました。
ストーリーボード
APPDELEGATE.H
//
// AppDelegate.h
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
APPDELEGATE.M
//
// AppDelegate.m
#import "AppDelegate.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@end
ENTERTAINMENTLISTING.H
//
// EntertainmentListingViewController.h
#import <UIKit/UIKit.h>
@interface EntertainmentListingViewController : UIViewController{
IBOutlet UITableView *mainTableView;
NSArray *events;
NSMutableData *data;
}
@end
ENTERTAINMENTLISTING.M
//
// EntertainmentListingViewController.m
#import "EntertainmentListingViewController.h"
#import "EntertainmentDetailsViewController.h"
@interface EntertainmentListingViewController ()
@end
@implementation EntertainmentListingViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
// VIEW TITLE
self.title = @"Entertainment";
// SHOW NETWORK ACTIVITY INDICATOR
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
//GET DATA URL
NSURL *url = [NSURL URLWithString:@"http://mydomain.com/myfile.php"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
//START CODE FOR TALBE VIEW
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
data = [[NSMutableData alloc] init];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)theData
{
[data appendData:theData];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
//PROCESS JSON DATA HERE
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
events = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
[mainTableView reloadData];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
// WASNT ABLE TO CONNECT INTERNET THROW ERROR
UIAlertView *errorView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"No Connection To The Internet Is Available" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
[errorView show];
// TURN OFF NETWORk ACTIVITY INDICATOR
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
- (int) numberOfSectionsInTableView: (UITableView *)tableView
{
return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 100;
}
- (int)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [events count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)IndexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MainCell"];
if(cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:@"MainCell"];
}
NSURL *url = [NSURL URLWithString: [[events objectAtIndex:IndexPath.row] objectForKey:@"eImg"]];
NSData *idata = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:idata];
UIImageView *imgView = [[UIImageView alloc] initWithImage:image];
cell.imageView.image = imgView.image;
cell.textLabel.text = [[events objectAtIndex:IndexPath.row] objectForKey:@"eName"];
cell.detailTextLabel.text = [[events objectAtIndex:IndexPath.row] objectForKey:@"date_string"];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
EntertainmentDetailsViewController *entertainmentdetailsViewController = [[EntertainmentDetailsViewController alloc]
initWithNibName:@"EntertainmentDetailsViewController" bundle:nil];
entertainmentdetailsViewController.title = [[events objectAtIndex:indexPath.row] objectForKey:@"eName"];
entertainmentdetailsViewController.entertainmentArticle = [events objectAtIndex:indexPath.row];
[self.navigationController pushViewController:entertainmentdetailsViewController animated:YES];
// NOTHING HAPPENING HAS TO DO WITH THIS AREA I THINK
NSLog(@"Navigation Cnntroller %@",self.navigationController);
NSLog(@"Events COntroller %@", entertainmentdetailsViewController);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
ENTERTAINMENTDETAILS.H
//
// EntertainmentDetailsViewController.h
#import <UIKit/UIKit.h>
@interface EntertainmentDetailsViewController : UIViewController{
NSDictionary *entertainmentArticle;
IBOutlet UILabel *titleLabel;
IBOutlet UILabel *timeLabel;
IBOutlet UITextView *descTextView;
}
@property (nonatomic, copy) NSDictionary *entertainmentArticle;
@end
ENTERTAINMENTDETAILS.M
//
// EntertainmentDetailsViewController.m
#import "EntertainmentDetailsViewController.h"
@interface EntertainmentDetailsViewController ()
@end
@implementation EntertainmentDetailsViewController
@synthesize entertainmentArticle;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
titleLabel.text = [entertainmentArticle objectForKey:@"eName"];
timeLabel.text = [entertainmentArticle objectForKey:@"date_string"];
descTextView.text = [entertainmentArticle objectForKey:@"eDetails"];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end