Custom Cell can't display in Table view in ios 6 - iphone

#import "MasterViewController.h"
#import "DetailViewController.h"
#interface MasterViewController ()
#end
#implementation MasterViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(#"Master", #"Master");
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
self.clearsSelectionOnViewWillAppear = NO;
self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0);
}
}
return self;
}
- (void)dealloc
{
[_detailViewController release];
[super dealloc];
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 5;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 100.0;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"CustomCell";
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier: CellIdentifier];
if (cell == nil)
{
cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.cellDate.text=#"date";
cell.cellDescription.text =#"Description";
cell.cellImageview.image = [UIImage imageNamed:#"facebook.png"];
cell.cellTitle.text = #"Title";
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
if (!self.detailViewController) {
self.detailViewController = [[[DetailViewController alloc] initWithNibName:#"DetailViewController_iPhone" bundle:nil] autorelease];
}
[self.navigationController pushViewController:self.detailViewController animated:YES];
}
else
{
}
}
#end
.h file
#import <UIKit/UIKit.h>
#import "CustomCell.h"
#import "XMLStringFile.h"
#class DetailViewController;
#interface MasterViewController : UITableViewController{
}
#property (strong, nonatomic) DetailViewController *detailViewController;
#property(strong,nonatomic)CustomCell *customCell;
#end
CustomCell.h
#import <UIKit/UIKit.h>
#interface CustomCell : UITableViewCell{
IBOutlet UIImageView *cellImageview;
IBOutlet UILabel *cellTitle;
IBOutlet UILabel *cellDescription;
IBOutlet UILabel *cellDate;
}
#property (retain, nonatomic) IBOutlet UIImageView *cellImageview;
#property (retain, nonatomic) IBOutlet UILabel *cellTitle;
#property (retain, nonatomic) IBOutlet UILabel *cellDescription;
#property (retain, nonatomic) IBOutlet UILabel *cellDate;
#end
CustomCell.m
#import "CustomCell.h"
#implementation CustomCell
#synthesize cellDate;
#synthesize cellDescription;
#synthesize cellImageview;
#synthesize cellTitle;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (void)dealloc {
[super dealloc];
}
#end
This is my both class
here Problem is in tableview data of the customcell cant Display onlt white screen.
Here i work in ios with masterdetails view template..
here i have also added m file in compile source
Customcell.xib size is 300X100
Here my output
My xib file as below
please help me to solve problem

if(cell == nil)
{
NSArray *outlets = [NSArray arrayWithArray:[[NSBundle mainBundle] loadNibNamed:#"CustomCell" owner:self options:nil]];
for(id obj in outlets)
{
if([obj isKindOfClass:[UITableViewCell class]])
{
cell = (CustomCell *)obj;
}
}
}
If your CustomCell is made via XIB then Write this Code where your cell is nil.
EDIT:-
This may be the cause - I think you haven't changed your CustomCell's class name. Follow these steps -
Take a XIB with name CustomCell.xib then delete its view.
Take a UITableViewCell and set its height and structure according to you.
Select File's Owner and change its class name to CustomCell, Same thing do with UITableViewCell... select it and change its class name to CustomCell.
Now connect all subView's IBOutLets.
Note:- Select IBOutLets by right clicking on UITableViewCell not from File's Owner.

Do the following in viewDidLoad
- (void)viewDidLoad
{
[super viewDidLoad];
UINib *nib = [UINib nibWithNibName:#"Customcell" bundle:nil];
[[self tableView] registerNib:nib forCellReuseIdentifier:#"CustomCell"];
}

If the cell is designed in a nib then you need to load the cell from the nib.
This actually has support in UIKit since iOS 5
What you need to do is register your nib with the UITableView.
- (void)viewDidLoad
{
[super viewDidLoad];
[self.tableView registerNib:[UINib nibWithNibName:#"Customcell" bundle:nil]
forCellReuseIdentifier:#"CustomCell"];
//...
}
Now your tableView:cellForRowAtIndexPath: just needs to look like this
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"CustomCell";
CustomCell *cell = (id)[tableView dequeueReusableCellWithIdentifier: CellIdentifier];
cell.cellDate.text = #"date";
cell.cellDescription.text = #"Description";
cell.cellImageview.image = [UIImage imageNamed:#"facebook.png"];
cell.cellTitle.text = #"Title";
return cell;
}
NB
Make sure to remember to set CustomCell as the reuseIdentifier in the xib
Some other observations
Really you should be using ARC for a new project.
#synthesize is implicit so not required in most cases
It's probably a bad idea to #import "CustomCell.h" in MasterViewController.h.
You should move this to the .m and use a forward declaration in the .h instead - #class CustomCell;
You also do not need to declare the backing ivars for properties as these will also be generated by the compiler e.g. you don't need to declare the following
#interface CustomCell : UITableViewCell {
IBOutlet UIImageView *cellImageview;
IBOutlet UILabel *cellTitle;
IBOutlet UILabel *cellDescription;
IBOutlet UILabel *cellDate;
}

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];

Table view is taking up the whole view instead of taking input width and height

I want a relatively small table view in my app. But I seem to have no luck because the table view is taking up the whole screen.
-(void)viewDidLoad{
UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0.0, 0.0, 20.0, 60.0) style:UITableViewStylePlain];
self.view = tableView;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyCellIdentifier = #"MyCellIdentifier";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:MyCellIdentifier];
if(cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyCellIdentifier];
}
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 5;
}
In your viewDidLoad method replace self.view = tableView to
[self.view addSubview:tableView];
You must create a property and give a name to your tableView:
#property(strong, nonatomic) IBOutlet UITableView* myTableView;
And after that you have to connect the delegate and do the
#synthesize myTableView;
Then use your code like that:
myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0.0, 0.0, 20.0, 60.0) style:UITableViewStylePlain];
Without this -> self.view = tableView;
I often ran into this problem. The best way in my experience to handle this, is to create a container view controller, that has the table vc as child vc.
I've created a simple class to manage that. You can just setup the vc in IB.
#import <UIKit/UIKit.h>
#interface ContainerViewController : UIViewController
#property (weak, nonatomic) IBOutlet UIView *contentViewPlaceholderView;
#property (strong, nonatomic) IBOutlet UIViewController *contentViewController;
#end
#import "ContainerViewController.h"
#interface ContainerViewController ()
#property (assign, nonatomic)BOOL isContentVCAdded;
#end
#implementation ContainerViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
[self setup];
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
[self setup];
}
return self;
}
- (void)setup
{
self.isContentVCAdded = NO;
}
- (void)insertAndShowContentVC
{
[self removeAllChildVCs];
self.contentViewController.view.frame = self.contentViewPlaceholderView.bounds;
[self addChildViewController:self.contentViewController];
[self.contentViewPlaceholderView addSubview:self.contentViewController.view];
[self.contentViewController didMoveToParentViewController:self];
self.isContentVCAdded = YES;
}
- (void)removeAllChildVCs
{
for (UIViewController *vc in self.childViewControllers) {
[vc willMoveToParentViewController:nil];
[vc.view removeFromSuperview];
[vc removeFromParentViewController];
}
}
- (void)setContentViewController:(UIViewController *)contentVC
{
_contentViewController = contentVC;
if (contentVC == nil) {
[self removeAllChildVCs];
}
else {
[self insertAndShowContentVC];
}
}
#pragma mark Lifecycle
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
if (nil != _contentViewController && !self.isContentVCAdded) {
[self insertAndShowContentVC];
}
}
#end
You just need to create a contentViewPlaceholderView (in IB or code) that has exactly the frame you want the table view to have. Then you just create your table vc as you like and set it as contentViewController of the ContainerViewController

Cannot navigate to the detail view in UITableView

I am trying to navigate to the detail view in the UITableView and seem to have some problems in executing it.
My code:
ViewController.h
#import <UIKit/UIKit.h>
#import "SecondViewController.h"
#interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>{
NSArray *tableItems;
NSArray *images;
}
#property (nonatomic,retain) NSArray *tableItems;
#property (nonatomic,retain) NSArray *images;
#end
ViewController.m
#import "ViewController.h"
#import <QuartzCore/QuartzCore.h>
#import "SecondViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize tableItems,images;
- (void)viewDidLoad
{
[super viewDidLoad];
tableItems = [[NSArray alloc] initWithObjects:#"Item1",#"Item2",#"Item3",nil];
images = [[NSArray alloc] initWithObjects:[UIImage imageNamed:#"clock.png"],[UIImage imageNamed:#"eye.png"],[UIImage imageNamed:#"target.png"],nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return tableItems.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//Step 1:Check whether if we can reuse a cell
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell"];
//If there are no new cells to reuse,create a new one
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:#"cell"];
UIView *v = [[UIView alloc] init];
v.backgroundColor = [UIColor redColor];
cell.selectedBackgroundView = v;
//changing the radius of the corners
//cell.layer.cornerRadius = 10;
}
//Set the image in the row
cell.imageView.image = [images objectAtIndex:indexPath.row];
//Step 3: Set the cell text content
cell.textLabel.text = [tableItems objectAtIndex:indexPath.row];
//Step 4: Return the row
return cell;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
cell.backgroundColor = [ UIColor greenColor];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
SecondViewController *detailViewController = [[SecondViewController alloc] initWithNibName:#"DetailViewController" bundle:nil];
[detailViewController printRowNumber:indexPath.row+1];
//NSArray *dataItem = [self.tableItems objectAtIndex:[indexPath row]];
//detailViewController.dataSource = dataItem;
[self.navigationController pushViewController:detailViewController animated:YES];
//[self presentViewController:detailViewController animated:YES completion:NULL];
}
#end
SecondViewController.h
#import <UIKit/UIKit.h>
#interface SecondViewController : UIViewController{
IBOutlet UILabel *lbl;
}
-(void) printRowNumber:(int)num;
#end
SecondViewController.m
#import "SecondViewController.h"
#interface SecondViewController ()
#end
#implementation SecondViewController
- (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.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void) printRowNumber:(int)num{
lbl.text = #"Hello";
NSLog(#"%d",num);
}
#end
I am able to print out the value of the indexPath.row in the output, but not able to show the detailview of the SecondViewController. Not sure what the problem is. Need some guidance...Thanks..
Have a look at this:
embed navigation controller
You need to embed your mainViewController in a NavigationController, if you want to use pushViewController: method.
If you do not want to use the NavigationController then you can use presentViewController: method to load the detailViewController and dismissViewController: method to return to the mainViewController

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.

#interface and multiple class names Objective-c

Original question
I have a class named RootViewController and my .h file has the code below
#import "SEViewController.h"
#interface RootViewController : SEViewController{
}
#end
and my SEViewController looks like
#interface SEViewController : UIViewController
{
}
#end
How can i declare RootViewController as UITableViewController and also as SEViewController the same time?
Edited question
Now I have the code below, but I get warnings and the table view does not appear.
RootViewController.m:
#import <UIKit/UIKit.h>
#import "ApplicationCell.h"
#import "SEViewController.h"
#interface RootViewController : SEViewController <UITableViewDataSource, UITableViewDelegate>
{
UITableView *tableView;
ApplicationCell *tmpCell;
NSArray *data;
}
#property (copy) NSArray *data;
#property(nonatomic,retain)UITableView *tableView;
#end
RootViewController.m:
#import "RootViewController.h"
#import "SubviewApplicationCell.h"
#define DARK_BACKGROUND [UIColor viewFlipsideBackgroundColor]
#define LIGHT_BACKGROUND [UIColor clearColor];
#implementation RootViewController
#synthesize data;
#synthesize tableView = _tableView;
#pragma mark -
#pragma mark View controller methods
- (void)viewDidLoad
{
NSString *dataPath = [[NSBundle mainBundle] pathForResource:#"rules" ofType:#"plist"];
self.data = [NSArray arrayWithContentsOfFile:dataPath];
self.navigationItem.title = #"rules";
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
self.tableView = [[UITableView alloc]init];
self.tableView.rowHeight = 73.0;
self.tableView.backgroundColor = DARK_BACKGROUND;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[super viewDidLoad];
}
- (void)viewDidUnload
{
self.data = nil;
[super viewDidLoad];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return YES;
}
#pragma mark -
#pragma mark Table view methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [data count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"ApplicationCell";
ApplicationCell *cell = (ApplicationCell *)[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[SubviewApplicationCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] autorelease];
}
cell.arrow = [UIImage imageNamed:#"circle"];
cell.name = [data objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.backgroundColor = LIGHT_BACKGROUND;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// [self.navigationController pushViewController:nil animated:YES];
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}
#pragma mark -
#pragma mark Memory management
- (void)dealloc
{
[data release];
[super dealloc];
}
#end
Why dont you make
#interface SEViewController : UITableViewController
{
}
Or, create SEViewController as UIViewController, put a table on it, and implement the UITableViewDelegate, and you are going to have the same.
#interface SEViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
}
For creating and adding a table to your view, use this code:
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect totalFrame = self.view.frame;
UITableView *myTableView = [[UITableView alloc] initWithFrame:totalFrame style:UITableViewStylePlain];
[self.view addSubview:myTableView];
[myTableView release];
}
Objective C doesn't support multiple inheritance. So RootViewController can't be a subclass of both SEViewController and UITableViewController.
However, you can make RootViewController conform to the protocols : UITableViewDelegate and UITableViewDataSource, and implement the corresponding methods.
#interface RootViewController : SEViewController < UITableViewDelegate, UITableViewDataSource>
// tableView declaration;
#property (strong, nonatomic) UITableView *tableView;
// ...
#end
#implementation RootViewController
#synthesize tableView = _tableView;
// ...
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// ...
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
// ...
}
// ...
Edit After you showed your complete code, I think the problem is here:
#interface RootViewController : SEViewController <UITableViewDataSource, UITableViewDelegate>
{
UITableView *tableView; // Remove this line
ApplicationCell *tmpCell;
NSArray *data;
}
Multiple inheritance is not possible in objective-c ,all you can do is to incorporate table view in SEViewController and declare delegate methods in it.. hoping this helps....
You can only inherit from one parent class, but it sounds like you just want to do...
#interface RootViewController : SEViewController <UITableViewDataSource, UITableViewDelegate> {