Why I got a "sent to freed object error"? - iphone

I have a Table View, and CharTableController, the CharTableController works like this:
.h:
#import <Foundation/Foundation.h>
#interface CharTableController : UITableViewController <UITableViewDelegate, UITableViewDataSource>{
// IBOutlet UILabel *debugLabel;
NSArray *listData;
}
//#property (nonatomic, retain) IBOutlet UILabel *debugLabel;
#property (nonatomic, retain) NSArray *listData;
#end
The .m:
#import "CharTableController.h"
#implementation CharTableController
#synthesize listData;
- (void)viewDidLoad {
NSArray *array = [[NSArray alloc] initWithObjects:#"Sleepy", #"Sneezy", #"Bashful", #"Happy", #"Doc", #"Grumpy", #"Dopey", #"Thorin", #"Dorin", #"Nori", #"Ori", #"Balin", #"Dwalin", #"Fili", #"Kili", #"Oin", #"Gloin", #"Bifur", #"Bofur", #"Bombur", nil];
self.listData = array;
[array release];
[super viewDidLoad];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.listData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *SimpleTableIdentifier = #"SimpleTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: SimpleTableIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:SimpleTableIdentifier] autorelease];
NSUInteger row = [indexPath row]; cell.textLabel.text = [listData objectAtIndex:row];
}
return cell;
}
#end
And I Use the IB to link the TableView's dataSource and delegate to the CharTableController.
In the CharTableController's view is the TableView in IB obviously. Reference Object in dataSource > TableView and delegate > TableView. What's wrong with my setting? thz.

How is listData filled ?
Maybe you add objects in the Array, then somewhere, these objects are released.
So listData reference a not more existing object.
Put a breakpoint in your object dealloc method to see when is being released and try to enable NSZombie.
Thierry

Related

ECSlidingViewController push data to table view

I am trying to use ECSlidingViewController which is available on github:
https://github.com/edgecase/ECSlidingViewController
Anyway I was wondering how to push data from the menu view controller to the sample table view controller because there is no segue. The navigation controller gets instantiated via storybaord but I see no way to push any data from view to another.
I tried now with delegates but it seems my delegate does not fire for some reason I dont know. The TableView stays empty. What did I miss?
Please see code below:
//MenuviewController.h
#import <UIKit/UIKit.h>
#import "ECSlidingViewController.h"
#protocol TableData <NSObject>
- (void) someData:(NSString*)data;
#end
#interface MenuViewController : UIViewController <UITableViewDataSource, UITabBarControllerDelegate>{
__unsafe_unretained id <TableData> delegate;
}
#property (nonatomic,assign) id <TableData> delegate;
#end
//MenuViewController.m
#import "MenuViewController.h"
#interface MenuViewController()
#property (nonatomic, strong) NSArray *menuItems;
#end
#implementation MenuViewController
#synthesize menuItems, delegate;
- (void)awakeFromNib
{
self.menuItems = [NSArray arrayWithObjects:#"First", #"Second", #"Third", #"Navigation", nil];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self.slidingViewController setAnchorRightRevealAmount:280.0f];
self.slidingViewController.underLeftWidthLayout = ECFullWidth;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sectionIndex
{
return self.menuItems.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellIdentifier = #"MenuItemCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
cell.textLabel.text = [self.menuItems objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *identifier = [NSString stringWithFormat:#"%#Top", [self.menuItems objectAtIndex:indexPath.row]];
UIViewController *newTopViewController = [self.storyboard instantiateViewControllerWithIdentifier:identifier];
if ([delegate respondsToSelector:#selector(someData:)]) {
[delegate someData:#"Hello World"];
}
[self.slidingViewController anchorTopViewOffScreenTo:ECRight animations:nil onComplete:^{
CGRect frame = self.slidingViewController.topViewController.view.frame;
self.slidingViewController.topViewController = newTopViewController;
self.slidingViewController.topViewController.view.frame = frame;
[self.slidingViewController resetTopView];
}];
}
#end
//SampleTableViewController.h
#import <UIKit/UIKit.h>
#import "ECSlidingViewController.h"
#import "MenuViewController.h"
#interface SampleTableViewController : UITableViewController <UITableViewDataSource, UITabBarControllerDelegate, TableData>
- (IBAction)revealMenu:(id)sender;
#end
//SampleTableViewController.m
#import "SampleTableViewController.h"
#interface SampleTableViewController()
#property (nonatomic, strong) NSArray *sampleItems;
#end
#implementation SampleTableViewController
#synthesize sampleItems;
- (void)awakeFromNib
{
//self.sampleItems = [NSArray arrayWithObjects:#"One", #"Two", #"Three", nil];
}
- (void) someData:(NSString *)data{
sampleItems = [NSArray arrayWithContentsOfFile:data];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sectionIndex
{
return self.sampleItems.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellIdentifier = #"SampleCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
cell.textLabel.text = [self.sampleItems objectAtIndex:indexPath.row];
return cell;
}
- (IBAction)revealMenu:(id)sender
{
[self.slidingViewController anchorTopViewTo:ECRight];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return YES;
}
#end
I would suggest using a delegate. Here is an example: Delegate example
I finally found out.
Here is an example.
UINavigationController *navigationController = [self.storyboard instantiateViewControllerWithIdentifier:identifier];
MBFancyViewController *viewController = navigationController.viewControllers[0];
//or alternative
MBFancyViewController *viewController = (MBFancyViewController *)navigationController.topViewController;
// setup "inner" view controller
viewController.foo = bar;
[self presentViewController:navigationController animated:YES completion:nil];

transform tableview

I want to images display for cell. but this code display, only white tableview.Why? Please tell me. (I use not storyboard.)
TableCell.h
#import <UIKit/UIKit.h>
#interface TableCell : UITableViewCell <UITableViewDelegate,UITableViewDataSource>
#property (nonatomic,retain) UITableView *tableCellView;
#property (nonatomic,retain) NSArray *cellArray;
-(NSString *)reuseIdentifier;
#end
TableCell.m
#import "TableCell.h"
#implementation TableCell
#synthesize tableCellView;
#synthesize cellArray;
-(NSString *)reuseIdentifier
{
return #"cell";
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [cellArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [self.tableCellView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
for (UIImageView *view in cell.subviews)
{
[view removeFromSuperview];
}
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 200, 200)];
imageView.image = [UIImage imageNamed:[cellArray objectAtIndex:indexPath.row]];
imageView.contentMode = UIViewContentModeCenter; // 画像サイズを合わせて貼る
CGAffineTransform rotateImage = CGAffineTransformMakeRotation(M_PI_2);
imageView.transform = rotateImage;
[cell addSubview:imageView];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 220;
}
#end
TableViewController.h
#import <UIKit/UIKit.h>
#class TableCell;
#interface TableViewController : UIViewController <UITableViewDataSource,UITableViewDelegate>
#property (nonatomic, retain) UITableView *tableView;
#property (nonatomic, retain) TableCell *tableViewCell;
#property (nonatomic, retain) NSArray *titlesArray;
#property (nonatomic, retain) NSArray *peopleArray;
#property (nonatomic, retain) NSArray *thingsArray;
#property (nonatomic, retain) NSArray *fruitsArray;
#property (nonatomic, retain) NSArray *arrays;
#end
TableViewController.m
#import "TableViewController.h"
#import "TableCell.h"
#interface TableViewController ()
#end
#implementation TableViewController
#synthesize tableView;
#synthesize tableViewCell;
#synthesize titlesArray;
#synthesize peopleArray;
#synthesize thingsArray;
#synthesize fruitsArray;
#synthesize arrays;
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView.delegate = self;
self.tableView.dataSource = self;
tableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] bounds] style:UITableViewStylePlain];
[self.view addSubview:tableView];
titlesArray = [[NSArray alloc] initWithObjects:#"People", #"Things", #"Fruits", nil];
peopleArray = [[NSArray alloc] initWithObjects:#"Gardener.png", #"Plumber.png", #"BusinessWoman.png", #"BusinessMan.png", #"Chef.png", #"Doctor.png", nil];
thingsArray = [[NSArray alloc] initWithObjects:#"StopWatch.png", #"TrashCan.png", #"Key.png", #"Telephone.png", #"ChalkBoard.png", #"Bucket.png", nil];
fruitsArray = [[NSArray alloc] initWithObjects:#"Pineapple.png", #"Orange.png", #"Apple.png", nil];
arrays = [[NSArray alloc] initWithObjects:peopleArray, thingsArray, fruitsArray, nil];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [arrays count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [titlesArray objectAtIndex:section];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 220;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
TableCell *cell = (TableCell *)[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:#"TableViewCell" owner:self options:nil];
CGAffineTransform rotateTable = CGAffineTransformMakeRotation(-M_PI_2);
tableViewCell.tableCellView.transform = rotateTable;
tableViewCell.tableCellView.frame = CGRectMake(0, 0, tableViewCell.tableCellView.frame.size.width, tableViewCell.tableCellView.frame.size.height);
tableViewCell.cellArray = [arrays objectAtIndex:indexPath.section];
tableViewCell.tableCellView.allowsSelection = YES;
cell = tableViewCell;
}
return cell;
}
#end
AppDelegate.m
TableViewController *tvc = [[TableViewController alloc] init];
self.window.rootViewController = tvc;
UITableViewCell by default already has support for images. You do not need to to add a new UIImageView as a subview ...
So instead of this:
for (UIImageView *view in cell.subviews)
{
[view removeFromSuperview];
}
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 200, 200)];
imageView.image = [UIImage imageNamed:[cellArray objectAtIndex:indexPath.row]];
imageView.contentMode = UIViewContentModeCenter; // 画像サイズを合わせて貼る
CGAffineTransform rotateImage = CGAffineTransformMakeRotation(M_PI_2);
imageView.transform = rotateImage;
[cell addSubview:imageView];
Write this:
cell.imageView.image = [UIImage imageNamed:[cellArray objectAtIndex:indexPath.row]];
Oh, I now notice that LOTS OF OTHER STUFF is wrong with your code! Sorry to say that. Other stuff you need to change:
Copy this method from your TableCell to your TableViewController: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath and remove the existing one
DELETE the TableCell class
I see you're also doing rotation... but leave that out for now. First try to make it work and THEN worry about rotation of the image.
Can I maybe advise you to read a book on iOS development? It seems as if you don't know what you're doing at all :(
But I do like to help you out. Can you maybe put all your code on http://www.github.com and invite me as a collaborator? My username is tomvanzummeren. I can make this app work for you.
your numberOfSectionsInTableView method might return 0. check the value of [arrays count]. And one more thing is you are not created UITableViewCell in proper way. That might be the problem too. Check this link for creating Custom UITableViewCell
Each UITableViewCell has an image support if it's style is default.
cell.imageView.image = yourImageView.image;
You don't need to do anything else.
You can change Image settings with changing yourImageView settings if you want.

Delegation in iOS

I have 2 ViewControllers, in 1st - TableView and in 2nd - button with label on it. When I click on the button in 2nd ViewController I need to go back on TableView and set in
cell.detailTextLabel.text
text from label on the button.
Here is my code, but it does not work:
ViewController.h:
#import <UIKit/UIKit.h>
#import "TestControl.h"
#interface ViewController : UIViewController <UITableViewDataSource, UITableViewDelegate, myTestProtocol>
{
TestControl *myProtocol;
}
#property (strong, nonatomic) IBOutlet UITableView * tableTest;
#end
ViewController.m:
#import "ViewController.h"
#import "TestControl.h"
#implementation ViewController
#synthesize tableTest;
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.navigationBarHidden = YES;
myProtocol = [[TestControl alloc]init];
myProtocol.delegate = self;
// Do any additional setup after loading the view, typically from a nib.
}
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 3;
}
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
TestControl * test = [[TestControl alloc] initWithNibName:#"TestControl" bundle:nil];
[self.navigationController pushViewController:test animated:YES];
}
- (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];
}
switch (indexPath.row) {
case 0:
cell.textLabel.text = #"Firs Cell";
cell.detailTextLabel.text = myProtocol.myLabel.text;
break;
case 1:
cell.textLabel.text = #"Second Cell";
break;
case 2:
cell.textLabel.text = #"Third Cell";
break;
default:
break;
}
return cell;
}
#end
TestControl.h:
#import <UIKit/UIKit.h>
#protocol myTestProtocol <NSObject>
#end
#interface TestControl : UIViewController
{
UILabel *myLabel;
}
#property (nonatomic, assign) id <myTestProtocol> delegate;
#property (strong, nonatomic) IBOutlet UILabel *myLabel;
- (IBAction)testButton:(id)sender;
#end
TestControl.m:
#implementation TestControl
#synthesize myLabel;
#synthesize delegate;
- (IBAction)testButton:(id)sender
{
myLabel.text = #"TEXT LABEL";
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES];
}
What is the problem in this???
A couple of things....
You are creating two different TestControl objects, setting the delegate for one of them and pushing the other one, so the one handling the button tap has no delegate.
The delegate logic would work better the other way around. That is, TestControl should have the code that communicates with its delegate rather than the delegate "pulling" from TestControl.

iPhone Bookmark UIWebView - Displaying Page Title and Storing URL

I have a fully operational web browser application that stores bookmarked pages. When the bookmarks button is clicked, a listview of the stored websites is displayed. Instead of showing the URL, I would like the listview to display the title of the page, but I would like the UIWebView to go to the URL when the title is clicked.
I have included the code below. I have also put the properties in both header files, but can't get it to work. Please help!
ExplorerViewController.h
#import <UIKit/UIKit.h>
#interface ExplorerViewController : UIViewController <UITextFieldDelegate, UIWebViewDelegate, UIActionSheetDelegate>{
UITextField *urlField;
UIBarButtonItem *refreshButton;
UIBarButtonItem *backButton;
UIBarButtonItem *forwardButton;
UIBarButtonItem *bookMarksButton;
UIActivityIndicatorView *loadingActivity;
UIWebView *webView;
UINavigationBar *navigationBar;
}
#property (nonatomic, retain) IBOutlet UITextField *urlField;
#property (nonatomic, retain) IBOutlet UIBarButtonItem *refreshButton;
#property (nonatomic, retain) IBOutlet UIBarButtonItem *backButton;
#property (nonatomic, retain) IBOutlet UIBarButtonItem *forwardButton;
#property (nonatomic, retain) IBOutlet UIBarButtonItem *bookMarksButton;
#property (nonatomic, retain) IBOutlet UIActivityIndicatorView *loadingActivity;
#property (nonatomic, retain) IBOutlet UIWebView *webView;
#property (nonatomic, retain) IBOutlet UINavigationBar *navigationBar;
-(NSString*)repairURL:(NSString*)url;
-(IBAction)refreshWebView;
-(IBAction)goBack;
-(IBAction)goForward;
-(void)actualizeButtons;
-(IBAction)bookmarksButtonTapped;
-(IBAction)addBookmarkButtonTapped;
#end
ExplorerViewController.m
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
NSMutableArray *bookmarks = [[[NSUserDefaults standardUserDefaults] arrayForKey:#"Bookmarks"] mutableCopy];
NSMutableArray *websitetitle = [[[NSUserDefaults standardUserDefaults] arrayForKey:#"Websitetitle"] mutableCopy];
if (!bookmarks) {
bookmarks = [[NSMutableArray alloc] init];
}
[bookmarks addObject:[[[[self webView]request] URL] absoluteString]];
[websitetitle addObject:[self.webView stringByEvaluatingJavaScriptFromString:#"document.title"]];
[[NSUserDefaults standardUserDefaults] setObject:bookmarks forKey:#"Bookmarks"];
[[NSUserDefaults standardUserDefaults] setObject:websitetitle forKey:#"Websitetitle"];
[bookmarks release];
[websitetitle release];
}
}
BookmarksViewController.h
#import <UIKit/UIKit.h>
#class ExplorerViewController;
#interface BookmarksViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>{
NSMutableArray *bookmarks;
NSMutableArray *websitetitle;
ExplorerViewController *explorerView;
}
#property (nonatomic, retain) NSMutableArray *bookmarks;
#property (nonatomic, retain) NSMutableArray *websitetitle;
#property (nonatomic, retain) ExplorerViewController *explorerView;
-(IBAction)cancelButtonTapped;
#end
BookmarksViewController.m
#import "BookmarksViewController.h"
#import "ExplorerViewController.h"
#implementation BookmarksViewController
#synthesize bookmarks, websitetitle, explorerView;
-(IBAction)cancelButtonTapped {
[self.parentViewController dismissModalViewControllerAnimated:true];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [bookmarks count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:cellIdentifier] autorelease];
}
cell.textLabel.text = [websitetitle objectAtIndex:indexPath.row];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
explorerView.urlField.text = [bookmarks objectAtIndex:indexPath.row];
[explorerView textFieldShouldReturn:explorerView.urlField];
[self.parentViewController dismissModalViewControllerAnimated:true];
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
[bookmarks removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationFade];
[[NSUserDefaults standardUserDefaults] setObject:bookmarks forKey:#"Bookmarks"];
}
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)dealloc
{
[super dealloc];
// e.g. self.myOutlet = nil;
[explorerView release];
explorerView = nil;
[bookmarks release];
bookmarks = nil;
}
You have to implement tableView:didSelectRowAtIndexPath:, roughly as follows:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *url=[bookmarks objectAtIndex:indexPath.row];
// open url here
}
A few considerations about your code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
explorerView.urlField.text = [bookmarks objectAtIndex:indexPath.row];
[explorerView textFieldShouldReturn:explorerView.urlField];
[self.parentViewController dismissModalViewControllerAnimated:true];
}
are you trying to replicate Mobile Safari?
you should probably avoid storing your bookmarks in the NSUserDefaults storage, and use a proper store.
you should not attempt to trigger a navigation action by simulating interaction events; the proper way to make a UIWebView (your underlying browser object) load a webpage is by using loadRequest:
The following code might work for you (I am relying on a lot of assumptions here):
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Get your url from the bookmarks object
NSString *urlString = [bookmarks objectAtIndex:indexPath.row];
// Convert to a URL object.
NSURL *url = [NSURL URLWithString:urlString];
// Create request
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[explorerView.webView loadRequest:requestObj];
// dismiss
[self.parentViewController dismissModalViewControllerAnimated:true];
}

iPhone App - Trouble Getting Cells To Display Array Data

I have a simple table view which I have built using an example from a book but it doesn't work..
It is supposed to take the values from an array and display them in the cells within a table view. I have connected the table views dataSource and delegate to the file's owner and have the following code in my controller class:
Simple_TableViewController.h
#interface Simple_TableViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
NSArray *listData;
}
#property (nonatomic, retain) NSArray *listData;
#end
Simple_TableViewController.m
#import "Simple_TableViewController.h"
#implementation Simple_TableViewController
#synthesize listData;
-(void)viewdidLoad{
NSArray *array = [[NSArray alloc] initWithObjects:#"Sleepy", #"Sneezy", #"Bashful", #"Happy", #"Doc", #"Grumpy", #"Dopey", #"Thorin",#"Dorin", #"Nori", #"Ori", #"Balin", #"Dwalin", #"Fili", #"Kili", #"Oin", #"Gloin", #"Bifur", #"Bofur", #"Bombur", nil];
self.listData = array;
[array release];
[super viewDidLoad];
}
- (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;
self.listData = nil;
[super viewDidUnload];
}
- (void)dealloc {
[listData release];
[super dealloc];
}
#pragma mark -
#pragma mark Table View Data Source Methods
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [self.listData count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *SimpleTableIdentifier = #"SimpleTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier] autorelease];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [listData objectAtIndex:row];
return cell;
}
#end
The project succeeds when compiling, but no text displays in the table cells...
UPDATE
#import <UIKit/UIKit.h>
#interface Simple_TableViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
IBOutlet UITableView *tv;
NSArray *listData;
}
#property (nonatomic, retain) NSArray* listData;
**#property (nonatomic, retain) UITableView* tv;**
#end
#import "Simple_TableViewController.h"
#implementation Simple_TableViewController
#synthesize listData, tv;
-(void)viewdidLoad{
NSArray *array = [[NSArray alloc] initWithObjects:#"Sleepy", #"Sneezy", #"Bashful", #"Happy", #"Doc", #"Grumpy", #"Dopey", #"Thorin",#"Dorin", #"Nori", #"Ori", #"Balin", #"Dwalin", #"Fili", #"Kili", #"Oin", #"Gloin", #"Bifur", #"Bofur", #"Bombur", nil];
self.listData = array;
**[tv reloadData];**
[array release];
[super viewDidLoad];
}
- (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;
self.listData = nil;
[super viewDidUnload];
}
- (void)dealloc {
[listData release];
[super dealloc];
}
#pragma mark -
#pragma mark Table View Data Source Methods
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [self.listData count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *SimpleTableIdentifier = #"SimpleTableIdentifier";
NSString *msg = #"message";
NSLog(#"%#", msg);
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier] autorelease];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [listData objectAtIndex:row];
return cell;
}
#end
You're missing the numberOfSections datasource method.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
Also after changing the data in your array, you'll want to reload the table.
[yourTableViewHere reloadData];
From your last comment,you made tableview from xib file but where is IBOutlet correspond to tableview. You have to make an IBOutlet UITableView *tableview and connect it with your tableview in xib file