button in cell with weblink - ios

I am trying to add a simple button to a custom cell that has a web link. I added the button in story board and associated it with houseLink. Here is my view.M file where I call the button from the custom cell.
#import "IBSecondViewController.h"
#import "C21TableCell.h"
#interface IBSecondViewController ()
#end
#implementation IBSecondViewController
{
NSArray *thumbnails;
}
#synthesize data;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//Initialize House Array
data = [NSArray arrayWithObjects:#"2109 E Avon Cricle, Hayden Lake, ID", #"703 E Garden, Coeur d' Alene, ID", nil];
_bedroom = [NSArray arrayWithObjects:#"3", #"4", nil];
// Initialize thumbnails
thumbnails = [NSArray arrayWithObjects:#"stockHouse.png", #"stockHouse2.png", nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view ddata source
- (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 *simpleTableIdentifier = #"C21TableCell";
C21TableCell *cell = (C21TableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"C21TableCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.addressLabel.text = [data objectAtIndex:indexPath.row];
cell.bedroomLabel.text = [_bedroom objectAtIndex:indexPath.row];
cell.thumbnailImageView.image = [UIImage imageNamed:[thumbnails objectAtIndex:indexPath.row]];
NOT SURE HOW TO CALL THE BUTTON HERE
return cell;
}
-(void) buttonpressed:(UIButton *)sender {
NSString* launchUrl = #"http://apple.com/";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: launchUrl]];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 78;
}
#end
C21TableCell.H
#import <UIKit/UIKit.h>
#interface C21TableCell : UITableViewCell
#property (nonatomic, weak) IBOutlet UILabel *addressLabel;
#property (nonatomic, weak) IBOutlet UILabel *bedroomLabel;
#property (nonatomic, weak) IBOutlet UIImageView *thumbnailImageView;
#property (nonatomic, weak) IBOutlet UIButton *homeLink;
#end
C21TableCell.M
#import "C21TableCell.h"
#implementation C21TableCell
#synthesize addressLabel = _nameLabel;
#synthesize bedroomLabel = _bedroomLabel;
#synthesize thumbnailImageView = _thumbnailImageView;
#synthesize homeLink = homeLink;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)awakeFromNib
{
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
#end

Just add target to button action when you create cell
[cell.homeLink addTarget:self action:#selector(buttonpressed:) forControlEvents:UIControlEventTouchUpInside];

Related

UITableView section header clickable Delegate not Call

I am new to ios development. I am create app in Storyboard, Initially UItableviewController with one prototype cells, with button and labels. The button has IBAction method in it UItableViewCell Class, the class has Delegate to UItableviewController,the delegate method does not called. But the Images in section view is change. The i post my full code here.
Download whole project from Link
ContactHeaderViewCell.h
#protocol SectionClick;
#protocol SectionClick <NSObject>
#optional
- (void) TickCheckbox : (NSInteger) section;
- (void) UnTickCheckbox : (NSInteger) section;
#end
#interface ContactHeaderViewCell : UITableViewCell
{
id<SectionClick> HeaderDelegate;
}
#property (strong, nonatomic) IBOutlet UILabel *lblName;
#property (strong, nonatomic) IBOutlet UIButton *btnCheckBox;
#property (strong, nonatomic) IBOutlet UIButton *btnArrow;
- (IBAction)btnCheckBox_click:(id)sender;
- (IBAction)btnArrow_Click:(id)sender;
#property (nonatomic, strong) id<SectionClick> HeaderDelegate;
#property (nonatomic) NSInteger section;
- (void) setDelegate:(id)delegate;
#end'
ContactHeaderViewCell.m
#implementation ContactHeaderViewCell
#synthesize HeaderDelegate,section;
- (void) setDelegate:(id)delegate
{
self.HeaderDelegate = delegate;
}
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (IBAction)btnCheckBox_click:(id)sender {
self.btnCheckBox.selected = !self.btnCheckBox.selected;
if (self.btnCheckBox.selected)
{
if ([self.HeaderDelegate respondsToSelector:#selector(UnTickCheckbox:)])
{
[self.HeaderDelegate UnTickCheckbox:self.section];
}
} else
{
if ([self.HeaderDelegate respondsToSelector:#selector(TickCheckbox:)])
{
[self.HeaderDelegate TickCheckbox:self.section];
}
}
}
ContactTableViewController.m
#import "ContactDetail.h"
#import "ContactHeaderViewCell.h"
#interface ContactTableViewController : UITableViewController<SectionClick>
#property(nonatomic) ContactDetail *contacts;
#property(nonatomic) NSMutableArray *ContactList;
#end
ContactTableViewController.m
#import "ContactTableViewController.h"
#import <AddressBook/AddressBook.h>
#import "ContactHeaderViewCell.h"
#import "UserDetailViewCell.h"
#interface ContactTableViewController ()
#end
#implementation ContactTableViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
}
return self;
}
- (void)viewDidLoad {
[self ArrayContactFunc];
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [self.ContactList count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
self.contacts =(self.ContactList)[section];
return (self.contacts.Isopen) ? [self.contacts.mobileNumbers count] : 0;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
static NSString *HeaderIdentifier = #"HeaderCell";
self.contacts = (self.ContactList)[section];
ContactHeaderViewCell *HeaderView = (ContactHeaderViewCell *)[self.tableView dequeueReusableCellWithIdentifier:HeaderIdentifier];
if (HeaderView == nil){
[NSException raise:#"headerView == nil.." format:#"No cells with matching CellIdentifier loaded from your storyboard"];
}
HeaderView.lblName.text = self.contacts.fullName;
if(self.contacts.IsChecked)
{
[HeaderView.btnCheckBox setImage:[UIImage imageNamed:#"Unchecked.png"] forState:UIControlStateSelected];
}
else
{
[HeaderView.btnCheckBox setImage:[UIImage imageNamed:#"Checked.png"] forState:UIControlStateSelected];
}
return HeaderView;
}
- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
self.contacts = (self.ContactList)[indexPath.section];
static NSString *DetailCellIdentifier = #"DetailCell";
UserDetailViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:DetailCellIdentifier];
if(!cell)
{
[NSException raise:#"headerView == nil.." format:#"No cells with matching CellIdentifier loaded from your storyboard"];
}
cell.lblDetail.text = (self.contacts.mobileNumbers)[indexPath.row];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 60.0;
}
-(void)UnTickCheckbox:(NSInteger)section
{
// self.contacts = (self.ContactList)[section];
// self.contacts.IsChecked = NO;
// [self.tableView reloadData];
}
-(void)TickCheckbox:(NSInteger)section
{
// self.contacts = (self.ContactList)[section];
// self.contacts.IsChecked = YES;
// [self.tableView reloadData];
}
Thank in advance.
You must add this line
[HeaderView setHeaderDelegate:self];
in method:
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;

UITableViewCellStyle Custom iOS 7

I'm having a bit confusion with the UITableViewCellStyle. I want to create a custom UITableViewCell like this:
But the text and the image not appear in the cell when I run the app. In Storyboard,I've put the TableView Style to 'Custom'.
What am I doing wrong?
MainTableViewController
#import "MainTableViewController.h"
#import "CustomMainCell.h"
static NSString *CellIdentifier = #"MainCell";
#interface MainTableViewController ()
//
#property(nonatomic, strong) NSArray *dataSource;
//
#property(nonatomic, strong) NSArray *iconsSource;
#end
#implementation MainTableViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = #"Currículum Vitae";
// Inicializo los arrays con los datos
self.dataSource = #[#"PERFIL",#"EXPERIENCIA",#"EDUCACIÓN",#"HABILIDADES",#"INTERESES"];
self.iconsSource = #[#"perfil.png",#"experiencia.png",#"educacion.png",#"habilidades.png",#"intereses"];
// Register Class for Cell Reuse Identifier
[self.tableView registerClass:[CustomMainCell class] forCellReuseIdentifier:CellIdentifier];
// This will remove extra separators from tableview
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
// Eliminio las líneas que separan las celdas
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return self.dataSource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomMainCell *cell = (CustomMainCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[CustomMainCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
cell.title.text = self.dataSource[indexPath.row];
cell.icon.image = self.iconsSource[indexPath.row];
return cell;
}
CustomMainCell.h
#interface CustomMainCell : UITableViewCell
//
#property (weak, nonatomic) IBOutlet UILabel *title;
//
#property (weak, nonatomic) IBOutlet UIImageView *icon;
#end
CustomMainCell.m
#import "CustomMainCell.h"
#implementation CustomMainCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self.textLabel.textColor = [UIColor brownColor];
}
return self;
}
- (void)awakeFromNib
{
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
#end
You shouldn't have:
// Register Class for Cell Reuse Identifier
[self.tableView registerClass:[CustomMainCell class] forCellReuseIdentifier:CellIdentifier];
because the cell is registered from the storyboard when the view controller is unarchived. By registering the class you are removing the archive (NIB) registration.
Additionally:
if (cell == nil) {
cell = [[CustomMainCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
shouldn't be required as you will always get a valid cell back (because the identifier is registered)

UITableViewCell Subtitle not showing up

I have my UITableView displaying JSON info being returned from a cloud code function. For some reason, it correctly displays the titles of the items being returned, but I can't get it to display the price as a subtitle of each cell. Setting the style as UITableViewCellStyleSubtitle doesn't seem to work, and gives me a warning stating Implicit conversion from enumeration type 'enum UITableviewCellStyle' to different enumeration type.
MatchCenterViewController.h:
#import <UIKit/UIKit.h>
#import <Parse/Parse.h>
#import "AsyncImageView.h"
#import "SearchViewController.h"
#interface MatchCenterViewController : UIViewController <UITableViewDataSource>
#property (nonatomic) IBOutlet NSString *itemSearch;
#property (nonatomic, strong) NSArray *imageURLs;
#property (strong, nonatomic) NSString *matchingCategoryCondition;
#property (strong, nonatomic) NSString *matchingCategoryLocation;
#property (strong, nonatomic) NSNumber *matchingCategoryMaxPrice;
#property (strong, nonatomic) NSNumber *matchingCategoryMinPrice;
#property (strong, nonatomic) NSArray *matchCenterArray;
#end
MatchCenterViewController.m:
#import "MatchCenterViewController.h"
#import <UIKit/UIKit.h>
#interface MatchCenterViewController () <UITableViewDataSource, UITableViewDelegate>
#property (nonatomic, strong) UITableView *matchCenter;
#end
#implementation MatchCenterViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// self.matchCenter = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
// _matchCenter.dataSource = self;
// _matchCenter.delegate = self;
// [self.view addSubview:self.matchCenter];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.matchCenter = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewCellStyleSubtitle];
self.matchCenter.frame = CGRectMake(0,50,320,self.view.frame.size.height-200);
_matchCenter.dataSource = self;
_matchCenter.delegate = self;
[self.view addSubview:self.matchCenter];
self.matchCenterArray = [[NSArray alloc] init];
}
- (void)viewDidAppear:(BOOL)animated
{
self.matchCenterArray = [[NSArray alloc] init];
[PFCloud callFunctionInBackground:#"MatchCenterTest"
withParameters:#{
#"test": #"Hi",
}
block:^(NSDictionary *result, NSError *error) {
if (!error) {
self.matchCenterArray = [result objectForKey:#"Top 3"];
dispatch_async(dispatch_get_main_queue(), ^{
[_matchCenter reloadData];
});
NSLog(#"Test Result: '%#'", result);
}
}];
[self.matchCenter registerClass:[UITableViewCell class] forCellReuseIdentifier:#"Cell"];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.matchCenterArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSDictionary *matchCenterDictionary= [self.matchCenterArray objectAtIndex:indexPath.row];
cell.textLabel.text = [matchCenterDictionary objectForKey:#"Title"];// title of the item
cell.detailTextLabel.text = [matchCenterDictionary objectForKey:#"Price"];// price of the item
return cell;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
#end
The cell you have registered is a default styled UITableViewCell, it does not have a subTitle. You can't change the style of the cell once it's created.
You basically have two options:
create a simple UITableViewCell subclass that uses UITableViewCellStyleSubtitle (or any other style of your choice)
#interface MyTableViewCell : UITableViewCell
#end
#implementation MyTableViewCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
// overwrite style
self = [super initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
return self;
}
#end
...
[self.matchCenter registerClass:[MyTableViewCell class] forCellReuseIdentifier:#"Cell"];
Or return to the old style dequeue technique where you create a cell if none could be dequeued
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
// if no cell could be dequeued create a new one
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
/* configure */
}
If you do this, you have to remove the registerClass:forCellReuseIdentifier: call.
I would go with option one, because most likely pretty soon you will figure out that the built in cells are very limited and you want to add your own views (e.g. labels, image views). And if you use a subclass you can use properties to access those views, and don't have to use hacks like tags to access them.
In Table View subtitle is not present otherwise you customize your cell
use detail text label
cell.detailTextLabel.text = [array objectForKey:#"Value"];

Calling a subview

#import "sideTableViewController.h"
#interface sideTableViewController ()
{
NSArray *colours;
}
#end
#implementation sideTableViewController
#synthesize colorNames;
#synthesize sideTableView;
- (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.
self.sideTableView.delegate= self;
self.sideTableView.dataSource=self;
colorNames = [NSArray arrayWithObjects:#"Archie",#"Sethi",#"Rajan" ,#"Deepak" ,nil];
}
- (NSInteger)sideTableView:(UITableView *)sideTableView numberOfRowsInSection:(NSInteger)section
{
return [colorNames count];
}
- (UITableViewCell *)sideTableView:(UITableView *)sideTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;
cell = [sideTableView dequeueReusableCellWithIdentifier:#"MyCell"];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"MyCell"];
}
cell.textLabel.text =[colorNames objectAtIndex:indexPath.row];
// NSLog(#"the indexpath is %#",indexPath);
return cell;
}
- (void)sideTableView:(UITableView *)sideTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [sideTableView cellForRowAtIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
[sideTableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
and this is the header file...
#import <UIKit/UIKit.h>
#interface sideTableViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
NSArray *colorNames;
}
#property (strong, nonatomic) IBOutlet UITableView *sideTableView;
-(IBAction)showMessage;
#property (nonatomic, retain) NSArray *colorNames;
#end
I'm trying to get an image as a background to an existing tableview.
i'm getting an exception regarding: [sideTableViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x7593640
please help i'm new in IOS programming!
may this code help you simply add the below code to just above
- (NSInteger)sideTableView:(UITableView *)sideTableView numberOfRowsInSection:(NSInteger)section
add this code
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}

cellForRowAtIndexPath doesn't work

On my xcode project I have a view with a tableview. I also have a "special" string that contains the objects to populate the array that populates the tableview.
Example:
NSString *myValues=[[NSString alloc]init];
myValues = #"aaa$bbb$ccc?111$222$333?";
as you can see the characters $ and ? separate the objects.
When I call the view I populate the array by the string but the tableview doesn't work. Here some code:
File.H:
#import <UIKit/UIKit.h>
#interface EquipaggioVC : UIViewController <UITableViewDelegate, UITableViewDataSource>{
UITableView *tableViewEquipaggio;
UITableViewCell *nibLoadedCell;
NSMutableArray *arrayEquipaggio;
NSString *stringaDati;
}
#property (nonatomic, retain) IBOutlet UITableView *tableViewEquipaggio;
#property (nonatomic, retain) IBOutlet UITableViewCell *nibLoadedCell;
#property (nonatomic, retain) NSMutableArray *arrayEquipaggio;
#property (nonatomic, retain) NSString *stringaDati;
#end
File.M:
#import "EquipaggioVC.h"
#import "AppDelegate.h"
#import "ClassEquipaggio.h"
#interface EquipaggioVC ()
#end
#implementation EquipaggioVC
#synthesize tableViewEquipaggio;
#synthesize nibLoadedCell;
#synthesize arrayEquipaggio;
#synthesize stringaDati;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
-(NSString *)uuid
{
//to create an ID
CFUUIDRef uuidRef = CFUUIDCreate(NULL);
CFStringRef uuidStringRef = CFUUIDCreateString(NULL, uuidRef);
CFRelease(uuidRef);
return [(NSString *)uuidStringRef autorelease];
}
-(void)loadTestData:(NSString*)stringaDatiArray{
//populate the array by the string.
if(stringaDatiArray!=nil){
NSArray *elenco=[stringaDatiArray componentsSeparatedByString:#"?"];
for (int i=0; i<([elenco count]-1) ; i++) {
NSString *dettagliEquipaggio=[[NSString alloc]init];
dettagliEquipaggio=[elenco objectAtIndex:i];
NSArray *dettagli=[dettagliEquipaggio componentsSeparatedByString:#"$"];
ClassEquipaggio *aEquipaggio=[[ClassEquipaggio alloc]init];
aEquipaggio.idMembro=[dettagli objectAtIndex:0];
aEquipaggio.sessoMembro=[dettagli objectAtIndex:1];
aEquipaggio.dataNascitaMembro=[dettagli objectAtIndex:2];
[arrayEquipaggio addObject:aEquipaggio];
[aEquipaggio release];
}
}
}
- (UITableViewCell *)tableView:(UITableView *)tableEquipaggioView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
static NSString *sLoadNibNamed;
UITableViewCell *cell;
ClassEquipaggio *aEquipaggio=[arrayEquipaggio objectAtIndex:indexPath.row];
cell = [tableEquipaggioView dequeueReusableCellWithIdentifier:CellIdentifier];
sLoadNibNamed=#"EquipaggioCell";
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:sLoadNibNamed owner:self options:NULL];
cell = [self typeNibLoadCell:aEquipaggio.idMembro];
}
// Configure the cell
UILabel *tipoSessoLabel = (UILabel*) [cell viewWithTag:1];
tipoSessoLabel.text = aEquipaggio.sessoMembro;
UILabel *dataNascitaLabel=(UILabel*)[cell viewWithTag:2];
dataNascitaLabel.text=aEquipaggio.dataNascitaMembro;
return cell;
}
-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{
return [arrayEquipaggio count];
}
-(UITableViewCell *)typeNibLoadCell:(NSString *)named{
return nibLoadedCell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return NO;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (void)viewDidLoad
{
[super viewDidLoad];
arrayEquipaggio=[[NSMutableArray alloc]init];
stringaDati=[[NSString alloc]init];
tableViewEquipaggio=[[UITableView alloc]init];
}
-(void)viewDidAppear:(BOOL)animated{
AppDelegate *appDelegate=(AppDelegate*)[[UIApplication sharedApplication]delegate];
UIBarButtonItem * btnIndietroa = [[[UIBarButtonItem alloc] initWithTitle:#"Indietro"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(editNavButtonPressed)]autorelease];
[self.navigationItem setLeftBarButtonItem:btnIndietroa];
stringaDati = [[NSUserDefaults standardUserDefaults] objectForKey:#"stringaDati"];
if(stringaDati!=nil){
[arrayEquipaggio removeAllObjects];
[self loadTestData:stringaDati];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)dealloc{
[super dealloc];
}
#end
On nib file the tableview has the connection with the delegate and datasource, as the IBoutlet is connected with it.
Thanks for your support.
EDIT: [arrayEquipaggio count] return 0.
By the looks of your question your problem is that the method cellForRowAtIndexPath is not being called and as you said the [arrayEquipaggio count] return 0.
Since you are using that array at the method numberOfRowsInSection with a return value of 0 is normal that your table is not calling the method cellForRowAtIndexPath. Since you are telling to your table that there are no rows.
If you want your table to be populated then check that your array return a value greater than 0.
In a nutshell It has no data to populate your table, that why it doesnt work.
Check that in your viewDidAppear:(BOOL)animated that your are pulling anything to stringaDati.
NSLog(#"info: %#",stringaDati);

Resources