IFTweetLabel in UITableViewCell Subclass not showing - ios5

Right Now I am making a twitter app and I am Using IFTweetLabel. I made a TableViewCell Subclass but When I Run it the label dosent show up.
Here is the .h:
#import <UIKit/UIKit.h>
#import "IFTweetLabel.h"
#interface twitterTextCell : UITableViewCell
#property (strong, nonatomic) IFTweetLabel *customtextLabel;
#end
And here is the implementation:
#import "twitterTextCell.h"
#implementation twitterTextCell
#synthesize customtextLabel;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
customtextLabel.backgroundColor = [UIColor orangeColor];
self.customtextLabel.frame = CGRectMake(240, 60, 345, 109);
[self addSubview:customtextLabel];
NSLog(#"Custom Label Text: %#", customtextLabel.text);
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
-(UILabel *)textLabel
{
return nil;
}
Here is the code that is in the cellforrow in the tableviewdelegate:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
twitterTextCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[twitterTextCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
NSDictionary *tweet = [self.timeLineData objectAtIndex:indexPath.row];
if ([tweet objectForKey:#"text"] != nil) {
NSString *allText = [[tweet objectForKey:#"text"] stringByDecodingHTMLEntities];
cell.customtextLabel.numberOfLines = 4;
cell.textLabel.numberOfLines = 4;
cell.customtextLabel.text = allText;
cell.textLabel.text = allText;
cell.customtextLabel.linksEnabled = YES;
NSDictionary *whoPostedTweet = [tweet objectForKey:#"user"];
cell.detailTextLabel.text = [whoPostedTweet objectForKey:#"name"];
NSURL *imageURL = [NSURL URLWithString:[NSString stringWithFormat:#"%#", [whoPostedTweet objectForKey:#"profile_image_url"]]];
[cell.imageView setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:#"placeholder.png"]];
cell.backgroundColor = [UIColor clearColor];
[cell.imageView.layer setCornerRadius:7.0f];
[cell.imageView.layer setMasksToBounds:YES];
return cell;
} else {
[self getTwitterData];
NSLog(#"nil called(else) ");
return cell;
}
return cell;
}
After all of this only the image and the detailtextview show up. I removing the default textview because If I don't the text shows up normally but it is not the IFTweetLabel. Another thing I have a question about is how do I reposition the detailtextabel so that it is Under the IFTweetLabel. Anything is greatly appreciated, I need help on both of these issues.

i think your problem is you are not allocating customTextLabel.
Just allocate the same before setting the background color in initWithStyle.
ie, self.customtextLabel = [[[IFTweetLabel alloc] init] autorelease];

Related

no images showing using a plist to populate in UITableview custom cell

I am trying to populate 2 images in a UITableView with information from a plist file.
Currently all of my label fields are populating however I am getting no images are showing. As I am new to this I am not quite sure whats wrong with the image code and I do not know where to go to from here. Any help to sort out the image code lines so the images populate in the UITableview would be appreciated.
My code is as follows:
#import "ViewController.h"
#import "MenuViewCell.h"
#interface ViewController ()
#property (copy, nonatomic) NSArray* tableData;
#end
#implementation ViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableData = [NSArray arrayWithContentsOfFile: [[NSBundle mainBundle] pathForResource: #"TestList" ofType: #"plist"]];
NSLog(#"%#",_tableData);
// 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)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:(BOOL)animated];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [_tableData count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
//return [[[_tableData objectAtIndex: section] objectForKey: #"Rows"] count];
NSDictionary *dataInSection = [[_tableData objectAtIndex: section] objectForKey: #"Rows"];
return [dataInSection count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return [[_tableData objectAtIndex: section] objectForKey: #"Title"];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = #"MenuCell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSDictionary *sectionData = _tableData[indexPath.section];
NSArray *rowsData = sectionData[#"Rows"];
NSDictionary *rowData = rowsData[indexPath.row];
UILabel *homeLabel = (UILabel *)[cell viewWithTag:100];
homeLabel.text = rowData[#"home"];
UILabel *homeScoreLabel = (UILabel *)[cell viewWithTag:101];
homeScoreLabel.text = rowData[#"homeScore"];
UILabel *awayLabel = (UILabel *)[cell viewWithTag:102];
awayLabel.text = rowData[#"away"];
UILabel *awayScoreLabel = (UILabel *)[cell viewWithTag:103];
awayScoreLabel.text = rowData[#"awayScore"];
UIImageView *homeImage = (UIImageView *)[cell viewWithTag:104];
homeImage.image = rowData[#"homeImage"];
UIImageView *awayImage = (UIImageView *)[cell viewWithTag:105];
awayImage.image = rowData[#"awayImage"];
return cell;
}
- (void)dealloc {
[_tableData release];
[super dealloc];
}
#end
At a minimum I would expect you need to do something like:
homeImage.image = [UIImage imageWithData:[rowData[#"homeImage"]];
Have you checked via debugging that _tableData contains the contents of the plist in the way you expect?

Can't dynamically create my custom cells on UITableView

I'm trying to create a UITableView in a UIViewController (I'd use UITableViewController but I want the UITableView to only use half of the screen space) that will create a new custom cell every time I press a button, and display the current time in that cell and the time since the last time I pressed the button (so the time in this cell minus the time in the cell above it).
The problem is, when I press the button, either nothing happens or, if I don't initialise the property I created for the UITableView, a blank cell appears.
My cell has 3 UILabel's in it, inOut, entryTime and delta, and the IBOutlet I created for the UITableView is timeTable. newEntry is the button. I have set my UITableView's datasource and delegate to my UIViewController, have "called" the protocols UITableViewDataSource, UITableViewDelegate on my UIViewController's header. I can't find what's wrong.
here's my code for the UIViewController:
#interface MainViewController ()
#property (strong, nonatomic) Brain *brain;
#end
#implementation MainViewController{
#private
NSMutableArray *_entryArray;
NSMutableArray *_timeSinceLastEntryArray;
}
#synthesize brain=_brain;
#synthesize timeTable=_timeTable;
- (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.
_brain = [[Brain alloc] init];
_entryArray = [[NSMutableArray alloc] init];
_timeSinceLastEntryArray = [[NSMutableArray alloc] init];
_timeTable = [[UITableView alloc] initWithFrame:CGRectZero];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [_entryArray count];
}
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier= #"Cell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if (indexPath.row%2==0){
cell.inOut.text = [NSString stringWithFormat:#"Entrada %d", indexPath.row/2 +1];
cell.entryTime.text = [NSString stringWithFormat:#"%#", [_entryArray objectAtIndex:indexPath.row]];
if (indexPath.row==0){
cell.delta.text=#"";
}
else {
cell.delta.text = [_timeSinceLastEntryArray objectAtIndex:indexPath.row];
}
}
else{
cell.inOut.text = [NSString stringWithFormat:#"SaĆ­da %d", (indexPath.row+1)/2];
cell.entryTime.text = [NSString stringWithFormat:#"%#",[_entryArray objectAtIndex:indexPath.row]];
cell.delta.text = [_timeSinceLastEntryArray objectAtIndex:indexPath.row];
}
return cell;
}
- (IBAction)newEntry:(id)sender {
[_entryArray addObject:[self.brain currentTime]];
NSInteger numberOfEntrys= [_entryArray count];
if (numberOfEntrys >1){
NSString *timeSinceLastEntry = [_brain timeSince:[_entryArray objectAtIndex:(numberOfEntrys-2)]];
[_timeSinceLastEntryArray addObject:timeSinceLastEntry];
}
else {
[_timeSinceLastEntryArray addObject:#"0"];
}
[_timeTable reloadData];
}
#end
and for CustomCell:
#implementation CustomCell
- (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
}
#synthesize inOut=_inOut, entryTime=_entryTime, delta=_delta;
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {
// Initialization code
_inOut = [[UILabel alloc]init];
_inOut.textAlignment = UITextAlignmentLeft;
_entryTime = [[UILabel alloc]init];
_entryTime.textAlignment = UITextAlignmentLeft;
_delta = [[UILabel alloc]init];
_delta.textAlignment = UITextAlignmentLeft;
[self.contentView addSubview:_entryTime];
[self.contentView addSubview:_inOut];
[self.contentView addSubview:_delta];
}
return self;
}
#end
Thanks for the help :)
I see you put the initialize code in
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier
But you create object with
cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
and you did not provided the Frame to the view that you created
_inOut = [[UILabel alloc]init];
_entryTime = [[UILabel alloc]init];
_delta = [[UILabel alloc]init];
Hope it helps you

how to add 2 object into a tableview cell

New to objective. I am trying to put 2 values into a table view. this is part of the code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.font = [UIFont systemFontOfSize:14]; //Change this value to adjust size
cell.textLabel.numberOfLines = 2;
NSString *desc= #"Alight Destination =";
cell.textLabel.text = desc,[alDescArray objectAtIndex:indexPath.row];
return cell;
}
for this line cell.textLabel.text = desc,[alDescArray objectAtIndex:indexPath.row];
the table only display Alight Destination = without adding in the values for [alDescArray objectAtIndex:indexPath.row];
What part did i do wrongly pls help
You should use
cell.textLabel.text=[NSString stringWithFormate:#"%# %#",desc,[alDescArray objectAtIndex:indexPath.row];
or
NSString *desc=[NSString stringWithFormart: #"Alight Destination = %#",[alDescArray objectAtIndex:indexPath.row] ];
cell.textLabel.text = desc;
`
Use following way...
cell.textLabel.text = [NSString stringWithFormat:#"%# %#",desc,[alDescArray objectAtIndex:indexPath.row]];
I think it will be helpful to you.
guess subclassing UITableViewCell will be useful. find code below hope it will help..!
# INTERFACE FILE
#import <UIKit/UIKit.h>
#interface CustomTableViewCell : UITableViewCell {
UIImageView *imageView;
UILabel *titleLabel1;
UILabel *titleLabel2;
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier;
- (void)setValuesForCell:(YourModal*)agent withIndexPath:(NSIndexPath*)indexPath;
#property(nonatomic,retain) UIImageView *imageView;
#property(nonatomic,retain) UILabel *titleLabel1;
#property(nonatomic,retain) UILabel *titleLabel2;
#end
#IMPLEMENTATION FILE
#implementation CustomTableViewCell
#synthesize titleLabel1,titleLabel2,imageView;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Your initialisation if any.
}
return self;
}
- (void)setValuesForCell:(YourModal*)modal withIndexPath:(NSIndexPath*)indexPath{
titleLabel1.text=modal.name;
titleLabel2.text=modal.description;
imageView.image=modal.image;
//Other values you want set from modal
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state.
}
- (void)dealloc {
[super dealloc];
[titleLabel1 release];
[titleLabel2 release];
//Other memory releases
}
#end
In your xib you can load the CustomTableViewCell as your class for viewing on tableview

get warning :UITableView dataSource must return a cell

I am having ViewAController:UITableViewController.I also have firstNameCell and lastNameCell like below
In ViewAController, I do
-(NSInteger)numberOfSectionsInTableView:(UITableView*)tableView {
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 50;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
if (indexPath.section == 0)
return firstNameCell;
return lastNameCell;
}
My question : why my cells are nil even though they are connecting to the cell in xib
Please advice me on this issue.
Your cellForRowAtIndexPath method does not initialize the cell properly.
It should contain code this -
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
It's possible you are being called before the nib has finished loading. Check to see if your -awakeFromNib method has been called yet.
Please try this:
static NSString *CellIdentifier = #"Cell";
cellVideoOptions *cell =(cellVideoOptions *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
and then init cell with nib name.
Do it programmatically:
CustomCell.h
#import <UIKit/UIKit.h>
#interface CustomCell : UITableViewCell
{
UILabel *firstName;
UILabel *lastName;
}
#property (nonatomic, retain) UILabel *firstName;
#property (nonatomic, retain) UILabel *lastName;
#end
CustomCell.m
#import "CustomCell.h"
#implementation CustomCell
#synthesize firstName, lastName;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
firstName = [[UILabel alloc]init];
firstName.textAlignment = UITextAlignmentLeft;
firstName.font = [UIFont boldSystemFontOfSize:18];
firstName.backgroundColor = [UIColor clearColor];
lastName = [[UILabel alloc]init];
lastName.textAlignment = UITextAlignmentLeft;
lastName.font = [UIFont boldSystemFontOfSize:14];
lastName.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:firstName];
[self.contentView addSubview:lastName];
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
CGRect contentRect = self.contentView.bounds;
CGFloat boundsX = contentRect.origin.x;
CGRect frame;
frame= CGRectMake(boundsX+7 ,7, 240, 20);
firstName.frame = frame;
frame= CGRectMake(boundsX+125 ,25, 220, 20);
lastName.frame = frame;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
}
- (void)dealloc
{
[firstName release];
[lastName release];
[super dealloc];
}
#end
In your ViewAController with TableView, dont forget import CustomCell.h
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
if (indexPath.section == 0) {
cell.firstName.text = #"firstname";
// and or cell.firstName.frame = ...
} else {
cell.lastName.text = #"lastname"
// and or cell.lastName.frame = ...
}
return cell;
}

How to make UITableView Like Below Image?

How to make UITableView like above image?
I know this is grouped table type. but how we can add the image+label+button to header of section.
I have tried
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
but it starts with CGRectMake(0,0,320,height).
I want just above section and exact width of section just like in image.
Thanks in advance.
Instead of trying to change the section header view, you might want to create a custom cell with a brown background, a label and a button and use it for the first row. So, in -cellForRowAtIndexPath, you could do something like
if (0 == indexPath.row) {
return brownCell;
} else {
return normalCell;
}
There are several ways to create custom cells, I always start from the Table View Programming Guide for iOS.
CustomCell.h
#import <UIKit/UIKit.h>
#interface CustomCell : UITableViewCell{
id delegate;
NSIndexPath *indexpath;
}
#property(nonatomic,assign) id delegate;
#property(nonatomic,retain)NSIndexPath *indexpath;
#property(nonatomic,retain) IBOutlet UIToolbar *Toolbar;
-(IBAction)SelectorLeft:(id)sender;
-(IBAction)SelectorRight:(id)sender;
#end
customcell.m
#import "CustomCell.h"
#import <QuartzCore/QuartzCore.h>
#implementation CustomCell
#synthesize Toolbar;
#synthesize delegate,indexpath;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
-(IBAction)SelectorLeft:(id)sender{
[delegate perfromselector:#selector(left:) withObject:indexpath];
}
-(IBAction)SelectorRight:(id)sender{
[delegate perfromselector:#selector(left:) withObject:indexpath];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
#end
UItbaleView part
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = #"identifier";
NSUInteger row = [indexPath row];
if (row == 0) {
CustomCell *cell = (CustomCell*)[tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
self.Cell = nil;
[[NSBundle mainBundle] loadNibNamed:#"CustomCell" owner:self options:nil];
cell = self.Cell;
}
cell.Toolbar.clipsToBounds=YES;
CALayer *l=cell.Toolbar.layer;
// set corner radious
[l setCornerRadius:10];
// to apply border on corners
[l setBorderColor:[[UIColor clearColor] CGColor]];
// to apply set border width.
[l setBorderWidth:5.0];
return cell;
}else{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease];
}
cell.textLabel.text = [NSString stringWithFormat: #"cell %i",row];
cell.delegate = self;
cell.indexpath = indexpath;
return cell;
}
return nil;
}
Also do n't forget to create Customcell.xib and add tool bar through interface builder
also create an outlet of CustomCell in tableview class and handle it as above
its easy all what you have to
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSUInteger row = [indexPath row];
if (row % 2 == 0) {
static NSString *identifier = #"RowOne";
UITableViewCell *cell = (RowTypeOne*)[tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault]autorelease];
}
cell.Title.text = [datasource objectatindex:row];
cell.Title.font = [UIFont fontWithName:#"Tahoma" size:16];
cell.contentView.backgroundColor = [UIColor redColor];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.textAlignment = UITextAlignmentRight;
return cell;
}else if (row % 2 == 1) {
static NSString *identifier = #"RowTwo";
UITableViewCell *cell = (RowTypeOne*)[tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault]autorelease];
}
cell.contentView.backgroundColor = [UIColor redColor];
cell.Title.text = [datasource objectatindex:row];
cell.Title.font = [UIFont fontWithName:#"Tahoma" size:16];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.textAlignment = UITextAlignmentRight;
return cell;
}
return nil;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
//create btn left each on handeled by selector
UIBarButtonItem *btnleft = [[UIBarButtonItem alloc] initWithTitle:#"List of sms" style:UIBarButtonItemStylePlain target:self action:#selector(ListClicked:)];
//create btn right each on handeled by selector
UIBarButtonItem *btnright = [[UIBarButtonItem alloc] initWithTitle:#"New" style:UIBarButtonItemStyleBordered target:self action:#selector(NewClicked:)];
//create uitoolbar then add btns to it as list of array
UIToolbar *tool = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
//change style of toolbar to be black
[tool setBarStyle:UIBarStyleBlack];
tool.items = [NSArray arrayWithObjects:btnleft,[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],btnright, nil];
//this is the parent view that we will add on it the uitoolbar objects and the buttons
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
[view autorelease];
[view addSubview:tool];
return view;
}
-(void)ListClicked:(id)sender{
//handle here btn left
}
-(void)NewClicked:(id)sender{
//handle here btn right
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 44;
}
if you want the cell not to be in the header you can check for first row in cellforrow at index path...
also if you want to do it in another style you can make custom cell and add it also to cellforrowatindexpath