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.
Related
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];
When I separated a ViewController included in TableView and TableViewDataSource files,
I got a run-time error : "..EXC_BAD_ACCESS ..".
There is whole source below.
// ViewController file
<ViewController.h>
#interface ViewController : UIViewController <UITableViewDelegate>
#property (strong, nonatomic) UITableView *tableView;
#end
<ViewController.m>
- (void)viewDidLoad
{
**DS1 *ds = [[DS1 alloc] init];**
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 100, 320, 200) style:UITableViewStylePlain];
_tableView.delegate = self;
**_tableView.dataSource = ds;**
[self.view addSubview:_tableView];
}
// TableViewDataSource file
<DS1.h>
#interface DS1 : NSObject <UITableViewDataSource>
#property (strong, nonatomic) NSArray *dataList;
#end
<DS1.m>
#import "DS1.h"
#implementation DS1
#synthesize dataList = _dataList;
- (id)init
{
self = [super init];
if (self) {
_dataList = [NSArray arrayWithObjects:#"apple",#"banana", #"orange", nil];
}
return self;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [_dataList 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];
}
cell.textLabel.text = [_dataList objectAtIndex:indexPath.row];
return cell;
}
#end
If I change the code of ViewController.m from
_tableView.dataSource = ds;
to
_tableView.dataSource = self;
, then it's ok. (Of course, after DataSource methods had been appended to ViewController.m)
I cannot find any problems, help me and thanks in advance.
If this is ARC you have to create an instance variable or a #property for your dataSource.
You allocate your dataSource ds as a local variable. But the dataSource property of the tableView does not retain ds. So at the end of viewDidLoad ARC will release ds and it gets deallocated.
save ds as a property of your viewController. like this:
#interface ViewController : UIViewController <UITableViewDelegate>
#property (strong, nonatomic) UITableView *tableView;
#property (strong, nonatomic) DS1 *dataSource;
#end
- (void)viewDidLoad
{
[super viewDidLoad]; // <-- !!!
self.dataSource = [[DS1 alloc] init];
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 100, 320, 200) style:UITableViewStylePlain];
_tableView.delegate = self;
_tableView.dataSource = self.dataSource;
[self.view addSubview:_tableView];
}
im working on a student project where I need to know which button in which row is clicked.
Each row has different labels, one like button and one dislike button.
I do know how to use NSIndexPath.row to detect which row is pressed, but In this case I need to know both which row and which buttton in that row is pressed.
I have searched all over SO for a good solution to detecting which row a button is clicked when having multiple buttons per row.
From what I understand reading the other posts, using button.tag can be very unpredictable so I rather use a different method if possible.
I have seen many apps that have this implemented, so there has to be an optimal way to do this. Does anyone have any good suggestions?
Code:
SearchCell.h
#interface SearchCell : UITableViewCell {
IBOutlet UIButton *likebutton2;
IBOutlet UIButton *dislikebutton2;
}
#property (nonatomic,retain) IBOutlet UILabel *track_label;
#property (nonatomic,retain) IBOutlet UILabel *artist_label;
#property (nonatomic,retain) IBOutlet UILabel *album_label;
#property (nonatomic,retain) IBOutlet UIButton *likebutton2;
#property (nonatomic,retain) IBOutlet UIButton *dislikebutton2;
#property (nonatomic, copy) void (^onButton)(UIButton *button);
- (void)buttonAction:(UIButton *)sender;
#end
SearchCell.m
#import "SearchCell.h"
#import "RootViewController.h"
#implementation SearchCell
#synthesize likebutton2, dislikebutton2, track_label, artist_label, album_label;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code.
}
return self;
}
- (void)buttonAction:(UIButton *)sender
{
self.onButton(sender);
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state.
}
- (void)dealloc {
[super dealloc];
}
#end
cellForRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *uniqueIdentifier = #"searchCell";
SearchCell *cell = nil;
Search *currentSearch = nil;
cell = (SearchCell *) [self.tableView dequeueReusableCellWithIdentifier:uniqueIdentifier];
if (tableView == [[self searchDisplayController] searchResultsTableView]) //Just from some previous debugging
{
currentSearch = [[searchxmlParser searchhits] objectAtIndex:indexPath.row];
}
if(!cell)
{
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:#"SearchCell" owner:nil options:nil];
for (id currentObject in topLevelObjects) {
if ([currentObject isKindOfClass:[SearchCell class]]) {
cell = (SearchCell *)currentObject;
[cell.likebutton2 addTarget:cell action:#selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
[cell.dislikebutton2 addTarget:cell action:#selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
cell.likebutton2.tag = 1;
cell.dislikebutton2.tag = 2;
break;
}
}
}
cell.onButton = ^(UIButton *theButton) {
[self handleButton:theButton indexPath:indexPath];
}
cell.track_label.text = [currentSearch track];
cell.artist_label.text = [currentSearch artist];
return cell;
}
Thank you for helping :)!
Why not do something like the following:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *reuseIdentifier = #"MyCell";
MyCustomCell *cell = (id)[tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
if (cell == nil) {
cell = [[[MyCustomCell alloc] init] autorelease];
[cell.firstButton addTarget:self action:#selector(firstButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[cell.secondButton addTarget:self action:#selector(secondButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
}
[cell.firstButton setTag:indexPath.row];
[cell.secondButton setTag:indexPath.row];
// other cell setup...
return cell;
}
- (void)firstButtonPressed:(id)sender {
NSInteger cellRow = [sender tag];
// do things...
}
- (void)secondButtonPressed:(id)sender {
NSInteger cellRow = [sender tag];
// do things...
}
This assumes that you only have one section in your UITableView, it's a bit more complicated to do this with multiple sections.
I think using blocks would be a good way to go, still using tags as in #EllNeal's solution:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *reuseIdentifier = #"MyCell";
MyCustomCell *cell = (id)[tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
if (cell == nil) {
cell = [[[MyCustomCell alloc] init] autorelease];
[cell.button1 addTarget:cell action:#selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
[cell.button2 addTarget:cell action:#selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
cell.button1.tag = 1;
cell.button2.tag = 2;
}
cell.onButton = ^(UIButton *theButton) {
[self handleButton:theButton indexPath:indexPath];
}
return cell;
Then your handler where you tell which button was pressed would be like this:
- (void)handleButton:(UIButton *)button indexPath:(NSIndexPath *)indexPath
{
//Use tag of button to identify which button was tapped, as well as the indexPath
}
Your cell code would look a bit like this:
#interface MyCustomCell
...
- (void)buttonAction:(UIButton *)sender
#property (nonatomic, copy) void (^onButton)(UIButton *button);
...
#end
#implementation
...
- (void)buttonAction:(UIButton *)sender
{
self.onButton(sender);
}
...
#end
Hope this helps!
Use the .tag property, it's very reliable and predictable.
If you think otherwise, show some code.
This is my first time using Three20 and I am trying to add a TTStyledTextLabel to my TTTableViewCell using the following code:
#interface ConvoreCell : TTTableViewCell{
TTStyledTextLabel * tt_title;
UITextView * title;
UILabel * detailed;
}
#property (nonatomic, retain) IBOutlet UITextView * title;
#property (nonatomic, retain) IBOutlet UILabel * detailed;
#property (nonatomic, retain) TTStyledTextLabel * tt_title;
#end
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
if (self == [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {
// Initialization code
tt_title = [[TTStyledTextLabel alloc] init];
tt_title.font = [UIFont systemFontOfSize:15];
[self.contentView addSubview:tt_title];
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
CGRect frame = tt_title.frame;
frame.size.width = 640;
frame.size.height = tt_title.text.height;
frame.origin.x = 45;
frame.origin.y = 5;
tt_title.frame = frame;
}
and in my TTTableView I have:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat titleHeight = [TTStyledText textFromXHTML:[[self.posts objectAtIndex:indexPath.row] message] lineBreaks:YES URLs:YES].height;
//NSLog(#"HEIGHT IS %f", titleHeight);
return titleHeight + 20;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"ConvoreCell";
ConvoreCell *cell = (ConvoreCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[ConvoreCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
TTImageView * avatar = [[TTImageView alloc] initWithFrame:CGRectMake(cell.frame.origin.x+5, cell.frame.origin.y+5, 40, 40)];
avatar.urlPath = [[[self.posts objectAtIndex:indexPath.row] creator] img];
avatar.userInteractionEnabled = YES;
avatar.tag = indexPath.row;
[cell addSubview:avatar];
cell.tt_title.text = [TTStyledText textFromXHTML:[[self.posts objectAtIndex:indexPath.row] message] lineBreaks:YES URLs:YES];
}
However, the layout is messy as hell. Why is this?
I cannot find anything wrong with your code.
Looking at the image, what strikes me is that the last row which is correcly displayed contains a link.
What I suspect is that it could be some bug in TTStyledText, which in my experience is not really suitable for displaying full HTML.
Could you try and confirm (or dismiss) this hypothesis? Is always so that a url in a row will make it "go crazy"?
In any case, it will help to set a breakpoint on (or an NSLog after) the line
cell.tt_title.text = [TTStyledText textFromXHTML:[[self.posts objectAtIndex:indexPath.row] message] lineBreaks:YES URLs:YES];
and check what is going in cell.tt_title.text.
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