Xcode is not reading any table view code i type


#1

i go into the m file and try to update my code with the text on pg 187 and it doesnt allow me to type it out it doesnt read "tableview and i get errors all over when i try and complete this chapter


#2

Did you declare that your BNRAppDelegate conforms to the UITableViewDataSource protocol?

Nick
http://myfirstiphoneapp.co.uk
http://easyintervalsapp.co.uk


#3

[quote=“fujilla”]Did you declare that your BNRAppDelegate conforms to the UITableViewDataSource protocol?

Nick
http://myfirstiphoneapp.co.uk
http://easyintervalsapp.co.uk[/quote]

ill be posting my code now i went through every step protocols still not my strong suite right now but i believe i did if it was in the text i have been working on this for 3 hours now


#4

so my code is not working i have retyped it multiple times now and every time it doesnt work i get stuck and the identifier “tableView” is not read. i really dislike how the transition on page 187 tells me to implement the code i do so in the M file but still get errors after following the directions here is my code.[

here is my header file

[code] //
// BNRAppDelegate.h
// itahdoodle
//
// Created by troy miller on 10/7/12.
// Copyright © 2012 troy miller. All rights reserved.
//

#import <UIKit/UIKit.h>
//declare a helper fucntion that will use to get a path to the location
// on the disc where we can save the to-do list
NSString *docPath(void);

@interface BNRAppDelegate : UIResponder <UIApplicationDelegate, UITableViewDataSource>

{
UITableView *taskTable;
UITextField *taskField;
UIButton *insertButton;
NSMutableArray *tasks;
}

-(void)addTask:(id)sender;

@property (strong, nonatomic) UIWindow *window;

@end
[/code]

here is my M file

[code] //
// BNRAppDelegate.m
// itahdoodle
//
// Created by troy miller on 10/7/12.
// Copyright © 2012 troy miller. All rights reserved.
//

#import “BNRAppDelegate.h”

NSString *docPath()
{
NSArray *pathList = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);
return [[pathList objectAtIndex:0] stringByAppendingPathComponent:@“data.td”];
}

@implementation BNRAppDelegate

#pragma mark - Application delegate callbacks

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    //attempt to load an exisiting to do data set from an array stored to the disck
    NSArray *plist = [NSArray arrayWithContentsOfFile:docPath()];

    if (plist) {
    //if there was a dataset avaible, copy into our instance variables
    tasks = [plist mutableCopy];
    } else {
    //other wise just create an empty one to get us started.x
    tasks = [[NSMutableArray alloc]init];
    }

// create and configure the Uiwindow instance
// a CGrect is a struct with an orgin (x,y.width,height)
CGRect windwoFrame = [[ UIScreen mainScreen]bounds];
UIWindow *theWindow = [[UIWindow alloc]initWithFrame:windwoFrame];
[self setWindow:theWindow];

//define the frame rectangles of the three ui elements
//cgrectmake creates a cbrect from x y width height
CGRect tableFrame = CGRectMake(0, 80, 320, 380);
CGRect fieldFrame = CGRectMake(20, 40, 200, 31);
CGRect buttonFrame =  CGRectMake (228, 40, 72, 31);

//create and configure the table view
taskTable = [[UITableView alloc]initWithFrame:tableFrame style:UITableViewStylePlain];
[taskTable setDataSource:self];
[taskTable setSeparatorStyle:UITableViewCellSeparatorStyleNone];




//create and configure a rounded rect insert button
insertButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[insertButton setFrame:buttonFrame];

//buttons behave using target/action call back
//configure the insert button action to call theis objects add task method

[insertButton addTarget:self action:@selector(addTask:)
       forControlEvents:UIControlEventTouchUpInside];

//give button a title
[insertButton setTitle:@"Insert"
              forState:UIControlStateNormal];


//add our three elements to the window
[[self window] addSubview:taskTable];
[[self window] addSubview:taskField];
[[self window] addSubview:insertButton];


//finalize the window and put it on the screen

[[ self window] setBackgroundColor:[UIColor whiteColor]];
[[ self window] makeKeyAndVisible];



return YES;

#pragma maek - Table View management
-(NSInteger)tableView:(tableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
return [task count];
}

-(UITableViewCell *)tableView: (UITableView)tableView
cellForRowAtIndexPath:(NSIntegerPath *)indexPath

{
    UITableViewCell *c = [taskTable dequeueReusableCellWithIndentifier:@"Cell"];
    
    if (!c){
        
           c = [[UITableViewCell alloc]initWithStyleDefault
                          resuseIndentifier:@"cell"];
    }
    
    NSString *item= [ tasks objectAtIndex: indexPath row]  ];
    
    [[c textLabel] setText:item];
    
    return c;
    }

}

  • (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
    [/code]

and the error i am receiving every time

2012-10-08 03:04:20.447 itahdoodle[1807:11303] Application windows are expected to have a root view controller at the end of application launch
2012-10-08 03:04:20.449 itahdoodle[1807:11303] -[BNRAppDelegate tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x7489e30
2012-10-08 03:04:20.450 itahdoodle[1807:11303] *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[BNRAppDelegate tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x7489e30’
*** First throw call stack:
(0x1c8d012 0x10cae7e 0x1d184bd 0x10de7ea 0x1c7ccf9 0x1c7c94e 0x1f66e8 0x1f93c4 0xbdfa2 0xbd92c 0xc1426 0xc60ce 0x6292d 0x10de6b0 0x2289fc0 0x227e33c 0x227e150 0x21fc0bc 0x21fd227 0x229fb50 0x109ff 0x114e1 0x22315 0x2324b 0x14cf8 0x1be8df9 0x1be8ad0 0x1c02bf5 0x1c02962 0x1c33bb6 0x1c32f44 0x1c32e1b 0x107da 0x1265c 0x225d 0x2185)
libc++abi.dylib: terminate called throwing an exception


#5

Your declaration of tableView:numberOfRowsInSection is wrong:

it should be:

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [tasks count];
}

You were pointing to an instance of (tableView *), whereas it should be (UITableView *).

I also noticed you were using
return [task count];
whereas the array is called tasks (plural).

Nick


#6

[quote=“fujilla”]Your declaration of tableView:numberOfRowsInSection is wrong:

it should be:

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [tasks count];
}

You were pointing to an instance of (tableView *), whereas it should be (UITableView *).

I also noticed you were using
return [task count];
whereas the array is called tasks (plural).

Nick[/quote]

seems in my sleepiness i made a few errors but i corrected them and they are still not reading “tableView” as an identifier


#7

What error(s) are you getting now?


#8

I have just noticed you haven’t close the application:didFinishingLaunchingWithOptions: method.

I wondered why all the other methods had been indented, and didn’t see it first time round.

Nick


#9

still quite new what do you mean not close it ? i try and add a } bracket and everything goes red after it


#10

Yeah, after
return YES;
close the method using the }

I have also noticed your tableView:cellForRowAtIndexPath: method has been declared wrong. I am guessing this is because you had to type in the whole statement, due to the fact that code completion was not working because the application:didFinishLaunchingWithOptions: had not been closed.

I suggest that after closing the application:didFinishLaunchingWithOptions: method, you delete your two tableView methods then start typing

  • tableView
    which will open code completion and show the available method options.

If you are still having trouble after this, could you please paste your latest code?

Nick


#11

i did figure out a way to close the method thanks for point that out now i actually got to type all the code in but then i press the insert button and the app crashes . there is no insert text box and i and can’t input text i believe…

/// here is the m file

[code]//
// BNRAppDelegate.m
// itahdoodle
//
// Created by troy miller on 10/7/12.
// Copyright © 2012 troy miller. All rights reserved.
//

#import “BNRAppDelegate.h”

NSString *docPath()
{
NSArray *pathList = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);
return [[pathList objectAtIndex:0] stringByAppendingPathComponent:@“data.td”];
}

@implementation BNRAppDelegate

#pragma mark - Application delegate callbacks

  • (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    //attempt to load an exisiting to do data set from an array stored to the disck
    NSArray *plist = [NSArray arrayWithContentsOfFile:docPath()];

    if (plist) {
    //if there was a dataset avaible, copy into our instance variables
    tasks = [plist mutableCopy];
    } else {
    //other wise just create an empty one to get us started.x
    tasks = [[NSMutableArray alloc]init];
    }

    if ([tasks count] == 0) {
    [tasks addObject:@“Walk the Dog”];
    [tasks addObject:@" Tell orrin he is a non -commiter"];
    [tasks addObject:@“play nba 2k13”];
    }

/////
// create and configure the Uiwindow instance
// a CGrect is a struct with an orgin (x,y.width,height)
CGRect windwoFrame = [[ UIScreen mainScreen]bounds];
UIWindow *theWindow = [[UIWindow alloc]initWithFrame:windwoFrame];
[self setWindow:theWindow];

//define the frame rectangles of the three ui elements
//cgrectmake creates a cbrect from x y width height
CGRect tableFrame = CGRectMake(0, 80, 320, 380);
CGRect fieldFrame = CGRectMake(20, 40, 200, 31);
CGRect buttonFrame =  CGRectMake (228, 40, 72, 31);

//create and configure the table view
taskTable = [[UITableView alloc]initWithFrame:tableFrame style:UITableViewStylePlain];
[taskTable setDataSource:self];
[taskTable setSeparatorStyle:UITableViewCellSeparatorStyleNone];




//create and configure a rounded rect insert button
insertButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[insertButton setFrame:buttonFrame];

//buttons behave using target/action call back
//configure the insert button action to call theis objects add task method

[insertButton addTarget:self action:@selector(addTask:)
       forControlEvents:UIControlEventTouchUpInside];

//give button a title
[insertButton setTitle:@"Insert"
              forState:UIControlStateNormal];


//add our three elements to the window
[[self window] addSubview:taskTable];
[[self window] addSubview:taskField];
[[self window] addSubview:insertButton];


//finalize the window and put it on the screen

[[ self window] setBackgroundColor:[UIColor whiteColor]];
[[ self window] makeKeyAndVisible];



return YES;

}

#pragma mark - Table View management
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
return [tasks count];
}

  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    UITableViewCell *c = [taskTable dequeueReusableCellWithIdentifier:@“Cell”];
    if (!c) {
    c = [[ UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@“Cell”];
    }

    NSString *item = [ tasks objectAtIndex:[indexPath row]];
    [[c textLabel]setText:item];

    return c;
    }

-(void)addTask:(id)sender
{
NSString *t = [taskField text];

if ([ t isEqualToString:@""]){
    return  ;
}


{
    [ tasks addObject:t];
    [taskTable reloadData];
    [taskField setText:@""];
    [taskField resignFirstResponder];
}

}

  • (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
    [/code]

h file

[code]//
// BNRAppDelegate.h
// itahdoodle
//
// Created by troy miller on 10/7/12.
// Copyright © 2012 troy miller. All rights reserved.
//

#import <UIKit/UIKit.h>
//declare a helper fucntion that will use to get a path to the location
// on the disc where we can save the to-do list
NSString *docPath(void);

@interface BNRAppDelegate : UIResponder <UIApplicationDelegate, UITableViewDataSource>

{
UITableView *taskTable;
UITextField *taskField;
UIButton *insertButton;
NSMutableArray *tasks;
}

-(void)addTask:(id)sender;

@property (strong, nonatomic) UIWindow *window;

@end
[/code]


#12

[quote=“fujilla”]Yeah, after
return YES;
close the method using the }

I have also noticed your tableView:cellForRowAtIndexPath: method has been declared wrong. I am guessing this is because you had to type in the whole statement, due to the fact that code completion was not working because the application:didFinishLaunchingWithOptions: had not been closed.

I suggest that after closing the application:didFinishLaunchingWithOptions: method, you delete your two tableView methods then start typing

  • tableView
    which will open code completion and show the available method options.

If you are still having trouble after this, could you please paste your latest code?

Nick[/quote]

thank you nick for all your help i fixed both of my problems i have the application working perfect right now !!!


#13

No problem, glad to help, and it’s good to hear you got it sorted.

Don’t be too disheartened by this chapter, as there is a lot to type in, and if you are planning on moving onto the BNR iOS Programming title afterwards, all will become clear.

Nick


#14

This problem is regarding Chapter 27, the section on Table View Management. My BNRDocument.h file is shown below; everything is fine until I type in

  • (NSInteger)tableView:(UITableView *) tableView numberOfRowsInSection:(NSInteger)section
    {
    return [tasks count];
    }

At this point the compiler complains (red stop symbol) and wants a semi-colon after “section”; of course when I ask it to “fix it” then it complains about the braces. I have entered the code several times.

//
// BNRAppDelegate.h
// iTahDoodle2
//
// Created by Dev Chakraborty on 10/10/12.
// Copyright © 2012 Dev Chakraborty. All rights reserved.
//

#import <UIKit/UIKit.h>

NSString *docPath (void);

@interface BNRAppDelegate : UIResponder <UIApplicationDelegate, UITableViewDataSource>

{
UITableView *taskTable;
UITextField *taskField;
UIButton *insertButton;

NSMutableArray *tasks;

}

#pragma mark - Table View Management

  • (NSInteger)tableView:(UITableView *) tableView numberOfRowsInSection:(NSInteger)section
    {
    return [tasks count];
    }

-(void)addTask:(id)sender;

@property (strong, nonatomic) UIWindow *window;

@end


#15

Hi There,

Firstly, I am rather confused by the fact that you say the name of your file is "BNRDocument.h ".

Also, your tableView:numberOfRowsInSection: method should be in the implementation (.m) file, not the interface file, which may be all you need to do.

Nick