Search code examples
iosxcodeuitableviewios6xcode4.6

How can I get my Table View in xcode 4.6 ios6 working?


I realize there are many posts like mine, but I still can't get the code working. Any help would be greatly appreciated.

I don't have all of the methods I want to implement implemented, so dont' worry about those. The error comes right after I link the tableview in the xib to the data source and delegate.

Let me know if I should post anything else that is relevant.

error:

2013-06-03 10:57:16.814 WID Sign-in[7587:11303] -[UITableView tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0xb3b0800
2013-06-03 10:57:16.816 WID Sign-in[7587:11303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableView tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0xb3b0800'
*** First throw call stack:
(0x1c94012 0x10d1e7e 0x1d1f4bd 0x1c83bbc 0x1c8394e 0x1fa548 0x1fd224 0xc1952 0xc12dc 0xc4dd6 0xc9a7e 0x662dd 0x10e56b0 0x2290fc0 0x228533c 0x2290eaf 0x1052bd 0x4db56 0x4c66f 0x4c589 0x4b7e4 0x4b61e 0x4c3d9 0x4f2d2 0xf999c 0x46574 0x4676f 0x46905 0x4f917 0x2cdb 0x13157 0x13747 0x1494b 0x25cb5 0x26beb 0x18698 0x1befdf9 0x1befad0 0x1c09bf5 0x1c09962 0x1c3abb6 0x1c39f44 0x1c39e1b 0x1417a 0x15ffc 0x291d 0x2845 0x1)
libc++abi.dylib: terminate called throwing an exception
(lldb) 

.h:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>{
    NSMutableArray *existingNames;
    NSMutableArray *existingCompanies;
    NSMutableArray *currentNames;
    NSMutableArray *currentCompanies;
IBOutlet UITableView *preExisting;
}


@property (nonatomic, retain) NSMutableArray *existingNames;
@property (nonatomic, retain) NSMutableArray *existingCompanies;
@property (nonatomic, retain) NSMutableArray *currentNames;
@property (nonatomic, retain) NSMutableArray *currentCompanies;

@property (weak, nonatomic) IBOutlet UITextField *name;

@property (weak, nonatomic) IBOutlet UITextField *company;


- (IBAction)add:(id)sender;
- (IBAction)addExisting:(id)sender;

@end

.m:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize name, company, existingNames, existingCompanies, currentNames, currentCompanies;

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [existingCompanies count]; // <------- here there is the problem with iOS 5.1, also [array1 count]
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 20;
}

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

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:
            UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"];
}

cell.textLabel.backgroundColor = [UIColor clearColor];
cell.detailTextLabel.backgroundColor = [UIColor clearColor];

cell.textLabel.text = [NSString stringWithFormat:@"📰 %@",[existingCompanies objectAtIndex:indexPath.row]];
cell.textLabel.font = [UIFont systemFontOfSize:13];
cell.textLabel.textColor = [UIColor blackColor];

return cell;
}


- (IBAction)add:(id)sender {
BOOL exists = [existingNames containsObject:name.text];

if(exists == FALSE){
    [existingNames addObject:name.text];
    [existingCompanies addObject:company.text];
}

[currentNames addObject:name.text];
[currentCompanies addObject:company.text];

name.text=@"";
company.text=@"";

// Set the delegate and datasource. Don't expect picker view to work
// correctly if you don't set it.

}

- (IBAction)addExisting:(id)sender {
}
@end

Solution

  • I had not initiated my NSMutableArrays correctly as well as declaring them in my .h, where this unnecessary. Thanks to those who tried to help!