Xcode4: Terminating app due to uncaught exception 'NSInternalInconsistencyException' - iphone

I am getting this Exception in xcode4 with the iphone simulator:
Terminating app due to uncaught exception 'NSInternalInconsistencyException'
It seems to be caused if you return no objects(return 0) back in the cellForRowAtIndex method. But I have mine set to return the cell.
Can anyone see what may be causing this error? Here is a bunch of screenshots:
Controller Configuration:
Prototype cell
attentionCell:
Storyboards:
Full Error:
**Assertion failure in -[UITableView
_createPreparedCellForGlobalRow:withIndexPath:],
/SourceCache/UIKit_Sim/UIKit-1914.84/UITableView.m:6061
2012-07-30 14:34:16.660 Simple Storyboard[263:f803] Terminating app due
to uncaught exception 'NSInternalInconsistencyException',
reason: 'UITableView dataSource must return a cell from
tableView:cellForRowAtIndexPath:'**
Here is the code:
#import "LWWBidTaskListController.h"
#interface LWWBidTaskListController ()
#property (strong, nonatomic)NSArray *tasks;
#end
#implementation LWWBidTaskListController
#synthesize tasks;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.tasks = [NSArray arrayWithObjects: #"Walk the dog", #"URGENT:Buy milk", #"Clean hidden lair", #"Invent miniature dolphins", #"Find new henchmen", #"Get revenge on do-gooder heroes", #"URGENT: Fold laundry", #"Hold entire hold hostage", #"Manicure", 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)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
self.tasks = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
//#warning Potentially incomplete method implementation.
// Return the number of sections.
//return 0;
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//#warning Incomplete method implementation.
// Return the number of rows in the section.
//return 0;
return [tasks count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath//populates each cell
{
//static NSString *CellIdentifier = #"Cell";
//UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSString *identifier = nil;
NSString *task = [self.tasks objectAtIndex:indexPath.row];
NSRange urgentRange = [task rangeOfString:#"URGENT"];
if (urgentRange.location == NSNotFound)
{
identifier = #"plainCell";
}
else
{
identifier = #"attentionCell";
}
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
// Configure the cell...
UILabel *cellLabel = (UILabel *)[cell viewWithTag:1];
cellLabel.text = task;
return cell;
}
What does that error mean and how can I fix it?

It looks as though you never create a cell. If you have never allocated and initialized a cell then there are none to dequeue.
before the // Configure the cell.. line you need to check if a reusable cell was dequeued and if not, create one like so:
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
// Configure common elements here
}
// Now go on to configure specific elements for this row
As you are using storyboard, perhaps you have not set up the prototype cell attributes correctly. The identifiers must match those in your method above.
See this pic for where you find the prototype cell attributes Prototype cell setup. it is from this tutorial that may help you as well Ray Wenderlich and Storyboards

I suppose that your second prototype cell has to be part of your tableView in the story board, right now its a part of same scene only - probably thats why you're getting nil.
Anyway try to:
NSLog(#"current cell: %# -> %#", identifier, cell);
and check what dequeueReusableCellWithIdentifier: is returning.
Just drag and drop attentionCell into table view

Related

UItbaleview Cell json contents not displayed in iOS

I created an app which will fetch info from web service.So far i got it by displaying the contents using NSLog but when i tried to load it in UITableViewCell its not displayed.Here is my code for that
#import "TableViewController.h"
#import "JSON.h"
#import "SBJsonParser.h"
#interface TableViewController ()
#end
#implementation TableViewController
#synthesize jsonurl,jsondata,jsonarray;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
}
jsonurl=[NSURL URLWithString:#"http://minorasarees.com/category.php"];
jsondata=[[NSString alloc]initWithContentsOfURL:jsonurl];
self.jsonarray=[jsondata JSONValue];
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)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#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 [jsonarray 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];
}
NSLog(#"1");
NSLog(#"%#",jsonarray);
cell.textLabel.text=[jsonarray objectAtIndex:indexPath.row];
NSLog(#"2");
return cell;
}
-(void)dealloc
{
[super dealloc];
[jsonarray release];
[jsondata release];
[jsonurl release];
}
#end
i've inserted tableviewcontroller by adding file with UITableViewController..will that be a problem..Help please..
Your JSON contains an array of dictionaries, so you're setting the text in your table view cell to an dictionary which cannot work since a string is expected. This actually should crash.
To solve that set your text to the category property of that dictionary:
cell.textLabel.text=[[jsonarray objectAtIndex:indexPath.row] valueForKey: #"category"];
besides this there are other things wrong with your code: [super dealloc] needs to be the last thing you call in your dealloc method. And you really should be using asynchronous networking code, blocking the main thread with networking is not acceptable.

Programmatically filled TableView error

I get this error when I scroll my table view down:
2012-04-23 09:32:36.763 RedFox[30540:207] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 12 beyond bounds [0 .. 11]'
*** First throw call stack:
(0x13c3052 0x1554d0a 0x13af674 0x5794 0xb3e0f 0xb4589 0x9fdfd 0xae851 0x59322 0x13c4e72 0x1d6d92d 0x1d77827 0x1cfdfa7 0x1cffea6 0x1cff580 0x13979ce 0x132e670 0x12fa4f6 0x12f9db4 0x12f9ccb 0x12ac879 0x12ac93e 0x1aa9b 0x2158 0x20b5)
terminate called throwing an exceptionsharedlibrary apply-load-rules all
Current language: auto; currently objective-c
An in my .h file I have:
#interface MyTableView : UIViewController <UITableViewDataSource> {
int currentRow;
}
#property (strong,nonatomic) UITableView *tableView;
#property (strong,nonatomic) ViewBuilder *screenDefBuild;
In my .m file:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [screenDefBuild.elementsToTableView count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = #"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];
}
ScreenListElements *currentScreenElement = [screenDefBuild.elementsToTableView objectAtIndex:currentRow]; //exception points here!
cell.textLabel.text = currentScreenElement.objectName;
currentRow++;
return cell;
}
- (void)viewDidLoad
{
[super viewDidLoad];
tableView = [[UITableView alloc] initWithFrame:self.view.bounds];
[tableView setDataSource:self];
[self.view addSubview:tableView];
}
What's wrong with that?
The currentRow variable is unnecessary and causing issues!
To fix:
change the line
ScreenListElements *currentScreenElement = [screenDefBuild.elementsToTableView objectAtIndex:currentRow]; //exception points here!
to
ScreenListElements *currentScreenElement = [screenDefBuild.elementsToTableView objectAtIndex:indexPath.row]; //exception points here!
Reason:
you increment the currentRow each time cellForARowAtIndexPath: is called, which is wrong, as this method in not only called when displaying following cells(when scrolling down) but also when you scroll up(so currentRow should decrement then). That's why Apple put the parameter indexPath so you can easyily determine which cell tableView is requesting.
The currentRow doesn't really make sense to me.
To return a cell containing a row of your source array (elementsToTableView)
you need to ask for the row in the current index path.
Your error-causing line should look like this:
ScreenListElements *currentScreenElement = [screenDefBuild.elementsToTableView objectAtIndex: indexPath.row];
And you don't need currentRow at all.
Why did you implement it that way?

iPad:Popover sample to iOS5

I am developing an app which will be used on both iPhone and iPad.
Today I've found that I should use Popover for iPad instead of PickerView on an action sheet.
I am trying to use a sample app use it on iOS5, but I have been getting an error;
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason:
'-[UITableViewController loadView] loaded the "2-view-5" nib but didn't get a UITableView.'
*** First throw call stack:
Do you know what exactly i need to do to fix that?
And, do you have any recommendation of popover examples for iOS5?
UYLMasterViewController.m
#import "UYLMasterViewController.h"
#import "UYLDetailViewController.h"
#implementation UYLMasterViewController
#synthesize detailViewController = _detailViewController;
#pragma mark -
#pragma mark === View Management ===
#pragma mark -
- (void)viewDidUnload
{
[super viewDidUnload];
self.detailViewController = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
#pragma mark -
#pragma mark === Table View Delegates ===
#pragma mark -
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 20;
}
- (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];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [NSString stringWithFormat:#"Item %u", row+1];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger item = [indexPath row] +1;
NSNumber *detailItem = [NSNumber numberWithInteger:item];
if (self.detailViewController)
{
self.detailViewController.detailItem = detailItem;
}
}
#end
If you didn't modify anything from the sample app, this is quite strange.
Anyway, I usually get this error when I forgot to set an IBOutlet connection from the table to the controller UITableViewController.
It is likely that you delete it by mistake, or Xcode lost its connection for some reason (it happens).
See if UYLMasterViewController.h is a UITableViewController. If yes, then the UITableView must be the first view in nib file, directly connected to the 'view' IBOutlet property of the controller.
Otherwise if UITableView is inside a UIView then you get the exact error you mentioned.
A probable solution, if UITableView is not the main view, would be to set UYLMasterViewController as a normal UIViewController and give it all the delegate accessor, then drag a connection from the UITableView to the controller, you will see that you have two options delegate and datasource, you need both.

Problem with sectioning UITableViewController

I have a class that extends UITableviewController which displays a data type called "GigData" (which only contains strings for now). The content is stored in "data" which is an NSMutableArray containing NSMutableArrays containing "GigData". This array is passed to the instance of my class and the arrays inside arrays make up the sections of the table. Here is the code I have implemented so far:
#synthesize data = _data;
- (id)init
{
self = [super initWithStyle:UITableViewStyleGrouped];
_data = [[NSMutableArray alloc] init];
[[self navigationItem] setTitle:#"Gigs by Date"];
return self;
}
- (id)initWithStyle:(UITableViewStyle)style
{
return [self init];
}
- (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
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return [_data count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [[_data objectAtIndex:section] 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];
}
NSMutableArray *sectionArray = [_data objectAtIndex:[indexPath section]];
GigData *gig =[sectionArray objectAtIndex:[indexPath row]];
[[cell textLabel] setText:[gig description]];
return cell;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
GigData *temp = [[_data objectAtIndex:section] objectAtIndex:0];
return [temp date];
}
When I run the app, I can see everything sorted into the right groups and all the displays are correct, except for the final section, which keeps changing names, some of which have included "cs.lproj", "headers" and "method not allowed". Scrolling to the bottom of the table then towards the top crashes the app. Also, if I provide my own implementation for description for "GigData", the app crashes even worse, I cannot scroll to the second section at all. Data is declared as a property in the header file and is set to nonatomic and retain. I have also tried using the code inside the init method to create the data array inside this class, but this makes no difference. Some runnings of the app have said there is a problem in tableView:cellForRowAtIndexPath: when I create "sectionArray". Has any body got any suggestions as to what I am doing wrong?

Iphone programming: Multiple UITableViews reading from the same source?

This question is related to UITableView issue when using separate delegate/dataSource, though I have a different problem. I'm just starting to learn iPhone programming.
Basically I have one main view with a table. On the event of a cell click, a sub view with another table is shown.
The datasource and delegate for the main view's table are set as files' owner, and I have added the necessary code in there to handle the table data and everything is fine.
But, when the second table in the sub-view seems to crash the application, I did the same thing, set the datasource and delegate to the file's owner and repeated the same procedure as for the main view's table. I have no idea why this is happening.
The sub-view has its only nib/xib file and its own outlet. If i do not attach any datasource to the subview's table, it takes the data from the main view's table; I don't understand why that is, since I have set the datasource to be the file's owner.
For example: the FirstView controller has a table FirstTable, the datasource and delegate are set to the owner of Files. I added the following in FirstView.m:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 4;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"LibraryListingCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text =#"Table Cell";
return cell;
}
Everything works perfectly.
The moment I repeat this with a second table and a second view, the application crashes saying
reason: '-[UISectionRowData tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x69188d0'
I have done exactly the same for second table: implemented numberOfRowsInSection and cellForRowAtIndexPatch inside secondview.m and set the second table's delegate and datasource to the file's owner. If I remove the delegate and datasource for the second table, the application doesn't crash but has an empty table in the second view.
Any suggestions? or am I missing some key concept here ?
You can use same datasource and delegate methods for multiple tables.
You have to mention in which table you are doing operations.
For example:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([tableView isEqual:TableView1])
{
//do work for tableview1
}
else if([tableView isEqual:TableView2])
{
//do operations for tableview2
}
}
This is the main View controller .h file.
#import <UIKit/UIKit.h>
#import "SubView.h"
#interface StackOverTableSubViewViewController : UIViewController <UITableViewDelegate,UITableViewDataSource>
{
UIView *contentView;
UITableView *tblVw;
NSMutableArray *array;
SubView *SubViewObj;
}
#property(nonatomic,retain) UIView *contentView;
#property(nonatomic,retain) UITableView *tblVw;
#property(nonatomic,retain) NSMutableArray *array;
#property(nonatomic,retain) SubView *SubViewObj;
#end
This is the main View controller .m file.
#import "StackOverTableSubViewViewController.h"
#implementation StackOverTableSubViewViewController
#synthesize contentView,tblVw,array,SubViewObj;
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
contentView=[[UIView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
contentView.autoresizingMask=(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
contentView.autoresizesSubviews=YES;
contentView.backgroundColor=[UIColor whiteColor];
tblVw=[[UITableView alloc]initWithFrame:[[UIScreen mainScreen]bounds] style:UITableViewStylePlain];
tblVw.dataSource=self;
tblVw.delegate=self;
tblVw.scrollEnabled=YES;
array=[[NSMutableArray alloc]init];
[array addObject:#"Row1"];
[array addObject:#"Row2"];
[array addObject:#"Row3"];
[array addObject:#"Row4"];
[array addObject:#"Row5"];
[array addObject:#"Row6"];
[array addObject:#"Row7"];
[array addObject:#"Row8"];
[array addObject:#"Row9"];
[array addObject:#"Row10"];
[array addObject:#"Row11"];
[array addObject:#"Row12"];
[contentView addSubview:tblVw];
self.view=contentView;
}
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section
{
return [array count];
}
// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"CellIdentifier";
// Dequeue or create a cell of the appropriate type.
// UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryNone;
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.numberOfLines = 0;
[cell.textLabel sizeToFit];
}
cell.textLabel.text=[array objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
SubViewObj=[[SubView alloc]init];
[self.view addSubview:SubViewObj.view];
}
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (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 {
[contentView release];
[SubViewObj release];
[tblVw release];
[array release];
[super dealloc];
}
#end
Add a view controller called subview. Here's subview.h:
#import <UIKit/UIKit.h>
#interface SubView : UIViewController <UITableViewDelegate,UITableViewDataSource>
{
UIView *contentView;
UITableView *tblVw;
NSMutableArray *array;
}
#property(nonatomic,retain) UIView *contentView;
#property(nonatomic,retain) UITableView *tblVw;
#property(nonatomic,retain) NSMutableArray *array;
#end
And subview.m:
#import "SubView.h"
#import
#implementation SubView
#synthesize contentView,tblVw,array;
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
contentView=[[UIView alloc]initWithFrame:CGRectMake(200, 10, 300, 600)];
contentView.autoresizingMask=(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
contentView.autoresizesSubviews=YES;
contentView.backgroundColor=[UIColor whiteColor];
tblVw=[[UITableView alloc]initWithFrame:CGRectMake(200, 10, 300, 600) style:UITableViewStylePlain];
tblVw.dataSource=self;
tblVw.delegate=self;
tblVw.scrollEnabled=YES;
tblVw.layer.borderWidth=4.0;
tblVw.layer.borderColor=[[UIColor redColor]CGColor];
array=[[NSMutableArray alloc]init];
[array addObject:#"Data1"];
[array addObject:#"Data2"];
[array addObject:#"Data3"];
[array addObject:#"Data4"];
[array addObject:#"Data5"];
[array addObject:#"Data6"];
[array addObject:#"Data7"];
[array addObject:#"Data8"];
[array addObject:#"Data9"];
[array addObject:#"Data10"];
[array addObject:#"Data11"];
[array addObject:#"Data12"];
[contentView addSubview:tblVw];
self.view=contentView;
}
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section
{
return [array count];
}
// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"CellIdentifier";
// Dequeue or create a cell of the appropriate type.
// UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryNone;
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.numberOfLines = 0;
[cell.textLabel sizeToFit];
}
cell.textLabel.text=[array objectAtIndex:indexPath.row];
return cell;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
return YES;
}
- (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 {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
#end
Try this code. This app was done for the iPad. Change the dimensions as needed for the iPhone.
I had the EXACT same issue and fixed it by deleting my connection from the table view's datasource to the files owner. Then I pasted in the code below replacing the existing cellForRowAtIndexPath. I had to change the array name to match my array and then reconnect the datasource to the files owner, and it started working. Must have been a snafu in my function code somewhere.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"CellIdentifier";
// Dequeue or create a cell of the appropriate type.
// UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryNone;
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.numberOfLines = 0;
[cell.textLabel sizeToFit];
}
cell.textLabel.text=[array objectAtIndex:indexPath.row];
return cell;
}