UITableView: error after connected table view to datasource - iphone

I'm trying to create a simple TableView in my current project.
but I got this error after connected datasource in IB and run iOS simulator.
2013-03-22 14:58:32.372 M[1875:c07] -[ViewController tableView:numberOfRowsInSection:]:
unrecognized selector sent to instance 0x88191f0
2013-03-22 14:58:32.374 M[1875:c07] *** Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[ViewController tableView:numberOfRowsInSection:]:
unrecognized selector sent to instance 0x88191f0'
,but when I create a simple TableView in an empty project with the same code it's working.
Here is my code
"MCEventActivityViewController.h"
#import <UIKit/UIKit.h>
#interface MCEventActivityViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
#end
"MCEventActivityViewController.m"
#import "MCEventActivityViewController.h"
#interface MCEventActivityViewController ()
#end
#implementation MCEventActivityViewController
{
NSArray *tableData;
}
- (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 from its nib.
tableData = [NSArray arrayWithObjects:#"1", #"2", #"3", nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [tableData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = #"SimpleTableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
return cell;
}
#end
Could anyone help me figure out why this error came out?
The screenshots are here.
Edited:

Make sure,
1.TableView is connected with FileOwner in XIB.
2.#interface Controller : UIViewController UITableViewDelegate,UITableViewDataSource included.
3.Delegate & DataSource both connected with FileOwner.
4.numberOfSections return 1.
5.numberOfRowsInSection returns [required].
6.cellForRowAtIndexPath
{ data goes here...
}
Edited:
Create,
#property (nonatomic,strong) IBOutlet UITabelView * tableView;
and connect this Outlet in Xib with Fileowner

Add numberOfSectionsInTableView method to your code
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
Add NSArray *tableData; to MCEventActivityViewController.h
and set its #property and #synthesize properly.
and write
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.tableData = [[NSArray alloc] initWithObjects:#"1", #"2", #"3", nil];
}

You should link the (dataSource and delegate) from Outlets to the view controller not to view ! like these pictures :

Related

program received signal SIGABRT (xcode)

#import <UIKit/UIKit.h>
#interface tableview : UIViewController<UITableViewDataSource>
{
NSArray *listOfItems;
}
#property(nonatomic,retain) NSArray *listOfItems;
#end
#import "tableview.h"
#implementation tableview
#synthesize listOfItems;
- (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];
}
//NSString *cellValue = [listOfItems objectAtIndex:indexPath.row];
cell.textLabel.text = [listOfItems objectAtIndex:indexPath.row];
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 3;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
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
{
listOfItems = [[NSArray alloc] initWithObjects:#"first",#"second",#"third", nil];
//listOfItems = [[NSMutableArray alloc]init];
// [listOfItems addObject:#"first"];
//[listOfItems addObject:#"second"];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
-(void)dealloc
{
[listOfItems release];
[super dealloc];
}
#end
2012-04-27 13:33:23.276 tableview test[438:207] -[UIView tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x6855500
2012-04-27 13:33:23.362 tableview test[438:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
'-[UIView tableView:numberOfRowsInSection:]: unrecognized selector
sent to instance 0x6855500'
* First throw call stack:
(0x13bb052 0x154cd0a 0x13bcced 0x1321f00 0x1321ce2 0x1ecf2b 0x1ef722 0x9f7c7 0x9f2c1 0xa228c 0xa6783 0x51322 0x13bce72 0x1d6592d
0x1d6f827 0x1cf5fa7 0x1cf7ea6 0x1d8330c 0x23530 0x138f9ce 0x1326670
0x12f24f6 0x12f1db4 0x12f1ccb 0x12a4879 0x12a493e 0x12a9b 0x2282
0x21f5)
terminate called throwing an exceptionCurrent language: auto; currently objective-c (gdb)
#interface tableview : UIViewController....
Instead of UIViewController try using UIView
I think you have missed UITableViewDelegate.
Your code is now incompleted. Your "tableView" is not the real UITableView, it's the UIViewController!
You should have the UITableView instance in your h file, and xib file, then link them each other, and set UITableViewDelegate proprty to your UIViewcontroller class.
Please check out the basic UITableView(Or UITableViewController) samples...

Signal SIGABRT in Xcode

I have table in which i would like to tap on the cell and it takes me to another table.
I got this error while running in Xcode 4.3.2 :
return UIApplicationMain(argc, argv, nil, NSStringFromClass([RanchForecastTouchAppDelegate class]));
Thread 1: Signal SIGABRT
I saw alot of answer related this error in this forum but it didn't work, it's the reason that I asked question again.
My code is:
CreateViewController.h
#import <UIKit/UIKit.h>
#interface CreateViewController : UIViewController <
UITableViewDataSource, UITableViewDelegate>
{
NSArray *tableData;
}
#property (nonatomic, retain) NSArray *tableData;
#end
CreateViewController.m
#import "CreateViewController.h"
#implementation CreateViewController
#synthesize tableData;
#pragma mark - View lifecycle
- (void)viewDidLoad
{
tableData = [[NSArray alloc] initWithObjects:#"Johan", #"Paul",#"George",#"Ringo", nil];
[super viewDidLoad];
// Do any additional setup after loading the view.
}
#pragma mark - TableView Data Source methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
{
return [tableData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
UITableViewCell *cell = nil;
cell = [tableView dequeueReusableCellWithIdentifier:#"MyCell"];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"MyCell"];
}
cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
return cell;
}
#end
Error message on console:
[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x68ab4d0
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x68ab4d0'
Edit:
#import "RanchForecastTouchViewController.h"
#interface RanchForecastTouchViewController ()
#end
#implementation RanchForecastTouchViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
#end
RanchForecastTouchViewController.h
#import <UIKit/UIKit.h>
#interface RanchForecastTouchViewController : UIViewController
#end
check your user interface connection, It would be for some wrong connections!
you added semicolons at the end of the line
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
{ ...
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{....
}
just remove them

Attempting to use table view in ios, getting error

I have a table view in my iOS tabbed application, but I can't run the app, I get this error at runtime:
3/23/12 10:15:23.119 PM CodeCompanion: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "2-view-16" nib but didn't get a UITableView.'
*** First throw call stack:
(0x13bd052 0x154ed0a 0x1365a78 0x13659e9 0x2436ae 0xda5cb 0xf5b89 0xf59bd 0xf3f8a 0xf3e2f 0xf1ffb 0xf285a 0xdbfbf 0xdc21b 0xdd0f1 0x4bfec 0x51572 0x4b72b 0x3abc2 0x3ace2 0x3aea8 0x41d9a 0x12be6 0x138a6 0x22743 0x231f8 0x16aa9 0x12a7fa9 0x13911c5 0x12f6022 0x12f490a 0x12f3db4 0x12f3ccb 0x132a7 0x14a9b 0x2888 0x27e5)
My View Controller header file is below:
#import <UIKit/UIKit.h>
#class LanguageTableViewCell;
#interface LanguagesViewController : UITableViewController {
NSArray *languages;
}
#property (nonatomic, retain) NSArray *languages;
#end
and my implementation file is:
#import "LanguagesViewController.h"
#import "LanguageTableViewCell.h"
#implementation LanguagesViewController
#synthesize languages;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(#"getting cell for row at index path: %i", [indexPath row]);
LanguageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"languageBase"];
if (cell == nil) {
cell = [[LanguageTableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:#"languageBase"];
}
[cell setName:[languages objectAtIndex:[indexPath row]]];
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(#"rows in section: %i is: %i", section, [languages count]);
return [languages count];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
NSLog(#"getting number of sections (1)");
return 1;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSLog(#"view loaded, setting array");
languages = [NSArray arrayWithObjects:#"Java", nil];
}
- (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
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
#end
I'm pretty new to xcode and objective-c, so mention anything that could have gone wrong. I have set the ViewController of the table view to my above class, and I am not getting any errors or warnings in xcode. The table view is one of those dynamic ones that use prototype cells. If I need to post the class of the cell, I will.
By the looks of your error message you're using a nib file, "2-view-16", to layout your view but it doesn't contain a UITableView (or it isn't hooked up).
The LanguagesViewController inherits from UITableViewController which is looking for a UITableView to control which doesn't exist.
If you're using a nib to setup the view, you'll need to add a UITableView to the nib and set it to be the tableView of your LanguagesViewController.

NSArray causing memory leak when simulated low memory warning

I have made a sample project that reproduces this issue which contains two views:
root header:
#import <UIKit/UIKit.h>
#import "view2.h"
#interface RootViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>{
view2 *secondView;
UITableView *table;
NSArray *array;
}
#property (nonatomic, retain) view2 *secondView;
#property (nonatomic, retain) IBOutlet UITableView *table;
#property (nonatomic, retain) NSArray *array;
#end
root main:
#import "RootViewController.h"
#implementation RootViewController
#synthesize table, array, secondView;
- (void)viewDidLoad
{
[super viewDidLoad];
if(self.array == nil){
self.array = [NSArray arrayWithObjects:#"1", #"2", #"3", #"4", nil];
}
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload
{
[super viewDidUnload];
table = nil;
array = nil;
secondView = nil;
}
- (void)dealloc
{
[table release];
[array release];
[secondView release];
[super dealloc];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [array count];
}
- (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];
}
cell.textLabel.text = [array objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (secondView == nil) {
secondView = [[view2 alloc] init];
}
[self.navigationController pushViewController:secondView animated:YES];
}
#end
view2 simple contains a label with the text "view 2" for identification purposes.
All this code is doing in the root controller is creating an array with the values 1,2,3,4 and binding this text as rows to the table, clicking any row pushes view 2 onto the stack.
if you load up the app in the simulator using the leaks instruments tool, click on any row so that view2 is displayed and then simulate an error warning the following leaks appear:
image
for the line:
self.array = [NSArray arrayWithObjects:#"1", #"2", #"3", #"4", nil];
this is causing me a lot of problems in my main app as i am using arrays to provide data in tables all over the place.
i have tried various ways to fix this such as declaring the array in different ways to no avail.
any help is greatly appreciated!
thanks
In viewDidUnload you're mixing up property vs. direct ivar access.
array = nil simply sets the ivar to nil without using the synthesized accessor method. You have to use the dot notation: self.array = nil;
This way the accessor setArray: is used which handles memory management for you.
Mixing up ivars and properties is a frequent problem amongst Objective-C beginners. The confusion can easily be prevented by always using different names for properties and ivars:
#synthesize array = _array;
You can just leave out the ivar declaration in the class's #interface or name it as in the #synthesize directive.

Tableview not drilling down

Ok, Here is the code in my AppDelegate that loads the Schedule nib.
Schedule *newestVideoController = [[Schedule alloc] initWithNibName:#"Schedule" bundle:nil];
newestVideoController.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"Schedule" image:[UIImage imageNamed:#"app-icon_2_newest.png"] tag:2];
NSArray *controllers = [NSArray arrayWithObjects:navController, newestVideoController, nil];
mainController.viewControllers = controllers;
Now here is my header file for schedule.
#import <UIKit/UIKit.h>
#import "AnotherViewController.h"
#interface Schedule : UITableViewController
<UITableViewDelegate, UITableViewDataSource> {
NSArray *mySchedule;
}
#property (nonatomic,retain) NSArray *mySchedule;
#end
Lastly here again is my implementaion file for "Schedule".
#import "Schedule.h"
#import "AnotherViewController.h"
#implementation Schedule
#synthesize mySchedule;
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return mySchedule.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//create a cell
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:#"cell"];
//fill it with contents
cell.textLabel.text = [mySchedule objectAtIndex:indexPath.row];
//return it
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:#"AnotherViewController" bundle:nil];
[self.navigationController pushViewController:anotherViewController animated:YES];
[anotherViewController release];
}
/*
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
}
return self;
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
NSString *myFile = [[NSBundle mainBundle] pathForResource:#"exercise" ofType:#"plist"];
mySchedule = [[NSArray alloc] initWithContentsOfFile:myFile];
[super viewDidLoad];
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (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.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
#end
Need more code/info. It looks like you implemented tableView:didSelectRowAtIndexPath: and pushed another View Controller onto the stack correctly, so it's hard to say. But here's a hit list:
Are you certain tableView:didSelectRowAtIndexPath: is getting called? Did you set a breakpoint? If not, you may have forgotten to set your Schedule class as the delegate either programatically or in Interface Builder.
Is schedule's navigation controller definitely set? That is, was it pushed onto a Navigation Controller stack?
Are you sure the nib file for AnotherViewController exists?