I created the simple Master Detail application for login.I deleted the MasterViewController, DetailViewController and Main.storyboard according to this tutorial:
Login app to mysql DB [part 1]
In AppDelegate didFinishLaunchingWithOptions function i made the following change
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window=[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]bounds] ];
/*UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
navigationController.topViewController.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem;*/
LoginTableViewController *loginTableViewController=[[LoginTableViewController alloc]initWithNibName:#"LoginTableViewController" bundle:nil ];
self.navigationController =[[UINavigationController alloc]initWithRootViewController:loginTableViewController];
self.window.rootViewController=self.navigationController;
[self.window makeKeyWindow];
return YES;
}
I commented this function from App Delegate function
/*
- (BOOL)splitViewController:(UISplitViewController *)splitViewController collapseSecondaryViewController:(UIViewController *)secondaryViewController ontoPrimaryViewController:(UIViewController *)primaryViewController {
.............................
}*/
I created LoginTableTableViewController with xib of subclass UITableViewController.
I created LoginTableTableViewController.h
#import "LoginTableViewController.h"
#interface LoginTableViewController ()
#end
#implementation LoginTableViewController
#synthesize arraylogin,userNameTextField,passwordTextField;
bool isKeyboardVisible=FALSE;
- (void)viewDidLoad {
[super viewDidLoad];
arraylogin=[[NSArray alloc] initWithObjects:#"user name",#"password",nil];
//set title
self.navigationItem.title=#"Best App";
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardAppeared) name:UIKeyboardDidShowNotification object:nil];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
-(void) loginAction
{
if([userNameTextField.text isEqualToString:#""] || [passwordTextField.text isEqualToString:#""])
{
// UIAlertView #alert=[[UIAlertView alloc] intitWithTitle:#"alert" messge:#"Please fill in all //the fields" delegate:self cancel]
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:#"alert" message:#"Please fill in all the fields" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[alert show];
//i will use a code to connect to DB turorial
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)keyboardAppeared
{
if(isKeyboardVisible==false)
{
isKeyboardVisible=true;
UIBarButtonItem *btnGo=[[UIBarButtonItem alloc] initWithTitle:#"Go" style:UIBarButtonItemStyleBordered target:self action:#selector(loginAction)];
self.navigationItem.rightBarButtonItem=btnGo;
}
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Incomplete implementation, return the number of sections
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete implementation, return the number of rows
return [arraylogin count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifer=#"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifer];
if (cell==nil)
{
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifer];
}
//cell are not selectable
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
CGRect frame;
frame.origin.x=10;
frame.origin.y=10;
frame.size.height=30 ;
frame.size.width= 200;
UILabel *label=[[UILabel alloc]initWithFrame:frame];
label.font=[UIFont boldSystemFontOfSize:16.0];
label.text=[arraylogin objectAtIndex:indexPath.row];
[cell.contentView addSubview:label];
frame.origin.x=110;
frame.size.height=90 ;
frame.size.width= 180;
// Configure the cell
if(indexPath.row==0)
{//username part
userNameTextField=[[UITextField alloc] initWithFrame:frame];
userNameTextField.returnKeyType=UIReturnKeyDefault;
[cell.contentView addSubview:userNameTextField];
}
else{//password part
passwordTextField=[[UITextField alloc] initWithFrame:frame];
passwordTextField.returnKeyType=UIReturnKeyDefault;
passwordTextField.secureTextEntry=YES;
[cell.contentView addSubview:passwordTextField];
}
return cell;
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationFade];
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*
/
/*
#pragma mark - Table view delegate
// In a xib-based application, navigation from a table can be handled in -tableView:didSelectRowAtIndexPath:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here, for example:
// Create the next view controller.
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:<##"Nib name"#> bundle:nil];
// Pass the selected object to the new view controller.
// Push the view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
}
*/
-(void) viewDidUnload
{
[super viewDidUnload];
self.arraylogin=nil;
self.userNameTextField=nil;
self.passwordTextField=nil;
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
#end
This program should be executing and show out like in this image
.
Execution stops program on some thread of main class function how i can remove this error and get the required output?You can download sample code from this link for correction.https://drive.google.com/file/d/0B5pNDpbvZ8SnV3Zab3VPM1B0a0k/view?usp=sharing
Your project is still specifying that a "Main" storyboard should be loaded. Edit your Info.plist file to remove the storyboard entry and it will get you past the current error.
(If you include error messages from your debug console when asking a question, it makes it easier on anyone trying to help. For example: "Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Could not find a storyboard named 'Main' in bundle".)
Related
I'm using this code in my app to pass data with the corresponding seque:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"readMoreDetail"]) {
MoreViewController *destinationViewController = segue.destinationViewController;
destinationViewController.openSubject = [self.detailItem description];
} else if ([segue.identifier isEqualToString:#"notesSegue"]) {
NSLog(#"segue");
NotesTableViewController *destinationViewController = segue.destinationViewController;
destinationViewController.openSubject = [self.detailItem description];
} else {
// Do nothing
}
}
I've embedded a UIViewController in a NavigationController and created a popover segue from another UIViewController to the NavigationController - but when I navigate I get this error:
-[UINavigationController setOpenSubject:]: unrecognized selector sent to instance 0x15e532a0
Any ideas why?
Thanks!
NotesTableViewController.h
#import <UIKit/UIKit.h>
#interface NotesTableViewController : UITableViewController <UINavigationControllerDelegate>
#property(nonatomic, strong)NSString *openSubject;
#end
NotesTableViewController.m
#import "NotesTableViewController.h"
#interface NotesTableViewController ()
{
NSMutableArray *_objects;
}
#end
#implementation NotesTableViewController
#synthesize openSubject;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
if (openSubject.length == 0) {
// There's currently no subject open, write it in the navigationbar
// Prompt = open subject
// Title = notes header
self.navigationItem.prompt = #"No subject selected";
self.navigationItem.title = #"My Notes";
} else {
// Open the subject
// Prompt = notes header
// Title = open subject
self.navigationItem.prompt = openSubject;
self.navigationItem.title = #"My notes";
// Load the notes data
// Create the key
NSString *partOfKey = #"-notes";
NSString *notesKey = [NSString stringWithFormat:#"%#%#", openSubject, partOfKey];
// Load the _objects from NSUserdefaults
_objects = [[NSUserDefaults standardUserDefaults] objectForKey:notesKey];
}
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
// Register a class or nib file using registerNib:forCellReuseIdentifier
// o registerClass:forCellReuiseIdentifier: method before calling this method
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:#"Cell"];
}
- (void)awakeFromNib
{
self.clearsSelectionOnViewWillAppear = NO;
self.preferredContentSize = CGSizeMake(320.0, 600.0);
[super awakeFromNib];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)addNote:(id)sender {
// Create a new note
if (openSubject.length == 0) {
// The openSubject is nil, can't add a subject - tell the user
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: #"No subject" message: #"Please select a subject prior to adding a note" delegate: nil cancelButtonTitle:#"OK" otherButtonTitles:nil]; [alert show];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"New note" message:#"Enter a note" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Add", nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert show];
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
// The user created a new subject, add it
if (buttonIndex == 1) {
// Get the input text
NSString *newNote = [[alertView textFieldAtIndex:0] text];
// Initialize objects
if (!_objects) {
_objects = [[NSMutableArray alloc] init];
}
// Check if the note already exist
if ([_objects containsObject:newNote]) {
// Tell the user this note already exists
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: #"Already exists" message: #"This note already exist, sorry" delegate: nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
} else {
// The note doesn't exist, add it
[_objects insertObject:newNote atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
// Save the new _objects
[self saveObjects];
}
}
}
-(void)saveObjects {
// Create the key
NSString *partOfKey = #"-notes";
// Save the new objects
NSString *notesKey = [NSString stringWithFormat:#"%#%#", openSubject, partOfKey];
[[NSUserDefaults standardUserDefaults] setObject:_objects forKey:notesKey];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return _objects.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell" forIndexPath:indexPath];
NSString *object = _objects[indexPath.row];
cell.textLabel.text = [object description];
return cell;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
[_objects removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationFade];
// Save the new objects
[self saveObjects];
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
}
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
#end
(I trust everyone to not steal this code)
If you trigger a segue to a UINavigationController the segue.destinationViewController will be the navigation controller and not the view controller contained in the navigation controller.
You can however get a reference to your NotesTableViewController:
UINavigationController *navController = segue.destinationViewController;
NotesTableViewController *notesTableVC = (NotesTableViewController *)[navController topViewController];
and then you can use
notesTableVC.openSubject = [self.detailItem description];
etc. to set the properties in your NotesTableViewController.
make sure your segue Identifiers are identified correctly as "notesSegue" and "readMoreDetail" , sometime you have to clean the project and run it again.
I'm going through the Apple Start Developing Guide and I have encountered an error in the demo app.
The code is as follows:
#import "XYZToDoListViewController.h"
#import "XYZToDoItem.h"
#interface XYZToDoListViewController ()
#property NSMutableArray *toDoItems;
-(void)viewDidLoad{
[super viewDidLoad];
self.toDoItems = [[NSMutableArray alloc]init];
[self loadInitialData];
}
#end
#implementation XYZToDoListViewController
-(void)loadInitialData{
XYZToDoItem *item1 = [[XYZToDoItem alloc]init];
item1.itemName = #"Buy Milk";
[self.toDoItems addObject:item1];
XYZToDoItem *item2 = [[XYZToDoItem alloc]init];
item2.itemName = #"Go Shopping";
[self.toDoItems addObject:item2];
XYZToDoItem *item3 = [[XYZToDoItem alloc]init];
item3.itemName = #"Wake Up";
[self.toDoItems addObject:item3];
}
- (IBAction)unwindToList:(UIStoryboardSegue *)segue
{
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.toDoItems count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"ListPrototypeCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
XYZToDoItem *toDoItem = [self.toDoItems objectAtIndex:indexPath.row];
cell.textLabel.text = toDoItem.itemName;
return cell;
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
/*
#pragma mark - Navigation
// In a story board-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
#end
On building it comes up with an error saying it expected ; after viewDidLoad.
I have googled this to see if I can figure out why but can't seem to.
put this in your .h file
#interface className : Class that you inherit
#property NSMutableArray *toDoItems;
#end
of course, you'd need to replace className with your name for the class, and the 'Class that you inherit' with the super classes such as NSObject, UIViewController, UIView, or any other class.
and put this in your .m file
#implementation className
-(void)viewDidLoad{
[super viewDidLoad];
self.toDoItems = [[NSMutableArray alloc]init];
[self loadInitialData];
}
#end
that should help.
Hope it helps :)
It looks like you might either have the property:
#property NSMutableArray *toDoItems;
In the implementation file (.m) or the method:
-(void)viewDidLoad{
...
}
In the header file (.h).
In addition you'll need an #implementation or #interface. Maybe you should update your question with the full code from the file.
The below property should be in .h file. Because in .h file we need to declare the method so property will declare the method which should be in .h file
#property NSMutableArray *toDoItems;
And below will be in .m file because in .m file we need to define the method.
- (void)viewDidLoad
{
[super viewDidLoad];
self.toDoItems = [[NSMutableArray alloc] init];
[self loadInitialData];
}
I have made an extremely simple app using Storyboards (for the first time).
The app's basically a Table View Controller embedded in a Navigation Controller and that segues out to a View Controller which displays an image. But when I click on an row, it gives me a Thread 1 SIGABRT error. Here's the log :
2013-09-03 22:37:16.669 FootballPlayers[7226:c07] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "PcV-xW-t12-view-xx8-ac-4rU" nib but didn't get a UITableView.'
* First throw call stack:
(0x1c94012 0x10d1e7e 0x1c93deb 0x245357 0xf6ff8 0xf7232 0xf74da 0x10e8e5 0x10e9cb 0x10ec76 0x10ed71 0x10f89b 0x10fe93 0xc4823f7 0x10fa88 0x46be63 0x45db99 0x45dc14 0xc5249 0xc54ed 0xacf5b3 0x1c53376 0x1c52e06 0x1c3aa82 0x1c39f44 0x1c39e1b 0x1bee7e3 0x1bee668 0x15ffc 0x226d 0x2195 0x1)
libc++abi.dylib: terminate called throwing an exception
Here's the implementation of the TableViewController
#import "PlayersTableViewController.h"
#interface PlayersTableViewController ()
#end
#implementation PlayersTableViewController
NSMutableArray *players;
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
DisplayViewController *dvc = [segue destinationViewController];
NSIndexPath *path = [[self tableView] indexPathForSelectedRow];
[dvc setCurrentPlayer:[players objectAtIndex:[path row]]];
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
players = [[NSMutableArray alloc] init];
Player *stevenGerrard = [[Player alloc] init];
[stevenGerrard setName:#"Steven Gerrard"];
[stevenGerrard setFileName:#"Steven Gerrard.jpg"];
[stevenGerrard setInformation:#"International Team : England, Club : Liverpool FC"];
[players addObject:stevenGerrard];
Player *cristianoRonaldo = [[Player alloc] init];
[cristianoRonaldo setName:#"Cristiano Ronaldo"];
[cristianoRonaldo setFileName:#"Cristiano Ronaldo.jpg"];
[cristianoRonaldo setInformation:#"International Team : Portugal, Club : Real Madrid"];
[players addObject:cristianoRonaldo];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [players count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"PlayerCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
Player *current = [players objectAtIndex:[indexPath row]];
[[cell textLabel] setText:[current name]];
return cell;
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:#"<#Nib name#>" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
*/
}
#end
What's wrong ?!
Thank You.
One very handy thing to do is to add an Exception Breakpoint: https://developer.apple.com/library/ios/recipes/xcode_help-breakpoint_navigator/articles/adding_an_exception_breakpoint.html
This way you'll probably see the exact place in your code where it goes wrong.
If the error occurs after tapping on a row, the code of the destination view controller is also interesting.
Your nib file is incorrectly constructed, most likely.
It would appear that you have something other than a table view connected to the table view controller's outlet that should point to the table view.
Make sure you are subclassing UITableViewController and not UIViewController (or anything else) in your .h file.
So it should look like:
#interface PlayersTableViewController : UITableViewController
I have this problem that when my code executes and then I click on item on table, it takes me to detail view. Things display properly but in the console there is this message:
2013-03-27 13:09:30.616 LinkTest[3605:c07] Unbalanced calls to
begin/end appearance transitions for
.
I know that this is reported here often and looked through the answers, but nothing seems to work. Maybe I got something wrong. Here is the code for tableviewcontroller:
#import "EventListingTableViewController.h"
#import "EventListingDetailViewController.h"
#interface EventListingTableViewController ()
#end
#implementation EventListingTableViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
-(void)fetchEventDetails
{
NSData *jsonData = [NSData dataWithContentsOfURL:[NSURL URLWithString:#"http://xsysdevelopment.com/ios/read.php"]];
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
self.eventsTitles = [[NSMutableArray alloc] init];
self.eventsCity = [[NSMutableArray alloc] init];
for(id object in dict){
[self.eventsTitles addObject:object[#"title"]];
[self.eventsCity addObject:object[#"city"]];
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self fetchEventDetails];
// Uncomment the following line to preserve selection between presentations.
//self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return self.eventsTitles.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
int row = [indexPath row];
cell.textLabel.text = self.eventsTitles[row];
cell.detailTextLabel.text = self.eventsCity[row];
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
EventListingDetailViewController *detailViewController = [[EventListingDetailViewController alloc] initWithNibName:#"EventListingDetailViewController" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"eventDetailSeague"])
{
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
EventListingDetailViewController *detailViewController = [segue destinationViewController];
int row = [indexPath row];
detailViewController.eventDetails = #[self.eventsTitles[row], self.eventsCity[row]];
}
}
I will really appreciate it if someone tells me where I am going wrong. I am new to iOS so only helpful criticism would be useful.
regards
If you are using segues via storyboards for the UITableView then you don't need the code in didSelectRowAtIndexPath:. I believe you a firing a push twice due to this.
I am very new to iOS programming. I am currently working on an app using storyboard, and I want to be able to display a series of 7 HTML files in a table, which when clicked on each one will then display an HTML file of formatted text.
I have googled to the ends of the earth and back and cannot find anything that answers my question on how to achieve this.
Basically the app has 4 tabs, the first is text, the second is the one where I want to display html files in a table (called Toolbox), the third is a web browser and the last is text.
I'm pretty sure I have my view controllers where they should be, but loading the html files into the table is not happening. I'm not getting any errors when building, I just get a blank table view on the tab when I run the app in simulator.
I'm not sure what other info I need to provide for anyone to help - below is a list of relevant files, and the code from the relevant h/m files. (I can't post images as yet)
Any help or advice would be greatly appreciated
List of Files:
AppDelegate.h
AppDelegate.m
globals.h
MainStoryboard_iPhone.storyboard
MainStoryboard_iPad.storyboard
ToolboxViewController.h
ToolboxViewController.m
chapter1.html
chapter2.html
chapter3.html
chapter4.html
chapter5.html
chapter6.html
chapter7.html
AppDelegate.h contains the following:
#import < UIKit/UIKit.h>
NSInteger articleIndex;
#interface AppDelegate : UIResponder < UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#end
AppDelegate.m contains the following:
#import "AppDelegate.h"
#import "ToolboxViewController.h"
#implementation AppDelegate {
NSArray *articleList;
}
#synthesize window = _window;
- (void)dealloc
{
[_window release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
articleList = [[NSArray arrayWithObjects:
#"chapter1",
#"chapter2",
#"chapter3",
#"chapter4",
#"chapter5",
#"chapter6",
#"chapter7",
nil] retain];
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
globals.h contains the following:
#ifndef TabAT_globals_h
#define TabAT_Viewer_globals_h
NSInteger articleIndex;
#endif
ToolboxViewController.h contains the following:
#import <UIKit/UIKit.h>
#import "globals.h"
#interface ToolboxViewController : UITableViewController
{
NSArray *articleList;
NSArray *articleNames;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
#end
ToolboxViewController.m contains the following:
#import "ToolboxViewController.h"
#import "globals.h"
#implementation ToolboxViewController
#synthesize window = _window;
#synthesize navigationController = _navigationController;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
articleNames = [[NSArray arrayWithObjects:
#"chapter1",
#"chapter2",
#"chapter3",
#"chapter4",
#"chapter5",
#"chapter6",
#"chapter7",
nil] retain];
articleList = [[NSArray arrayWithObjects:
#"What is Anxiety",
#"Anxiety Symptoms",
#"Coping Skills",
#"Visualisation",
#"Treatment",
#"Places to go for help",
#"About",
nil] retain];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [articleList count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"ToolboxCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
cell.textLabel.text = [articleList objectAtIndex:indexPath.row];
return cell;
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:#"<#Nib name#>" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
*/
Your implementation of ToolboxViewController.m is incomplete. In your code both numberOfSectionsInTableView: and numberOfRowsInSection: are returning 0, which is why nothing is appearing in your table. From what I can tell of your app's description they should return 1 and the length of your articleList array, respectively. Also you will need to set the contents of the table cells in cellForRowAtIndexPath:.
You could do something like the following:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [articleList length];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// here's where you set the content inside your table cell
cell.textLabel.text = [articleList objectAtIndex:[indexPath row]];
return cell;
}
That should be enough to get you started.